At the end of a week in which he discovered he had not made the Great Britain squad for the Olympics, Beckham had something to smile about when he equalised Steven Lenhart's seventh-minute opener with a trademark free kick on the half-hour.
An own goal from Jason Hernandez and Landon Donovan's strike - capitalising on a defensive mess in the San Jose box - made it 3-1 but Victor Bernardez pulled one back before the break.
Sam Cronin equalised two minutes after the restart and Chris Wondolowski completed Beckham's miserable week in the 61st minute.
The win also extended the Earthquakes' lead at the top of the Western Conference to four points over Real Salt Lake, which lost 2-0 at Columbus Crew.
Tony Tchani and Eddie Gaven struck in the first half for Columbus.
DC United established a two-point lead at the top of the Eastern Conference with a 3-0 win over Montreal Impact.
Chris Pontius put DC ahead on the stroke of half-time, Robbie Russell added a second five minutes into the second half and substitute Hamdi Salihi completed the scoring in the dying moments.
That put United two clear of New York Red Bulls, which only drew 1-1 at Toronto FC.
Jan Gunnar Solli put the Red Bulls up in the fourth minute but the lead lasted just two minutes before Danny Koevermans equalised.
Seattle Sounders lost ground on the West leaders with a 2-2 draw at New England Revolution.
Eddie Johnson scored twice before the break as the Sounders responded to Saer Sene's opener, but substitute Diego Fagundez struck moments from the end to ensure the spoils were shared.
Brian Ching scored an 83rd-minute penalty 10 minutes after stepping off the bench to give Houston Dynamo a 1-0 win over Philadelphia Union.
Houston led through Brad Davis' strike in the 19th minute before Keon Daniel levelled a minute into the second half.
Colorado Rapids beat Portland Timbers 3-0 with goals from Jaime Castrillon, Conor Casey and Jamie Smith.