The Earthquakes went into the 74th minute down 2-0, but Steven Lenhart scored off a corner kick and Khari Stephenson converted a penalty kick to tie the score. Just seconds before time expired. Gordon finished a bouncing cross for the winning goal.
Hector Jimenez and Mike Magee scored for Los Angeles.
The Galaxy went ahead in third minute when Jimenez sent a close-range shot past San Jose goalkeeper Jon Busch for his first MLS goal.
Los Angeles played a man down after Jimenez received a red card in the 60th minute for a tackle on Earthquakes defender Steven Beitashour. Still, the Galaxy doubled their lead on Magee's goal in the 73rd minute.