Omar Gonzalez tied it in the 61st minute with a long header for the Galaxy, who defended their title in a rematch of last season's championship game.
With a stirring second-half surge capped by Robbie Keane's goal on another penalty kick in injury time, Los Angeles won its fourth MLS Cup, tying D.C. United for the MLS record.
The Galaxy also gave an appropriate farewell to Beckham, the 37-year-old English midfielder who transformed the league and his team over six seasons in Los Angeles. Beckham will play elsewhere in the new year before eventually returning to MLS as a team owner, but he hasn't disclosed his immediate plans.
After Calen Carr put Houston ahead in the 44th minute, Beckham and his high-scoring teammates systematically broke down the defense of the Dynamo, who lost the MLS Cup 1-0 to Los Angeles on the same field last year.
Keane played another stellar attacking game for Los Angeles before earning his own penalty kick when Houston's Tally Hall knocked him down in the box, while Gonzalez got the equalizer on a cagey play by MLS' top defender last season.
Donovan even redeemed himself for missing an open net in the 13th minute by burying his penalty kick after a Houston handball in the box. The U.S. national team star, who is also contemplating a departure from soccer, won his record-tying fifth MLS title while scoring his fifth career MLS Cup goal and the record 22nd goal of his postseason career.
After Keane's goal clinched it, Beckham left the game to a raucous standing ovation from the packed stadium amid chants of "Thank you, David!" Beckham hugged Galaxy coach Bruce Arena, who won his fourth MLS title, and just about everybody on the Galaxy bench before the game ended moments later.
Beckham streamed onto the field with his teammates and waved thanks at the fans before he was joined by his three sons, all clad in No. 23 Galaxy jerseys.
The pregame rain cleared long enough for MLS' sunny farewell to Beckham, who arrived in Los Angeles in 2007 from Real Madrid with designs on changing the American perception of the world's most popular game. The league has grown steadily during his tenure, with most MLS franchises on sound financial footing and in excellent stadiums, although the sport's popularity and TV ratings haven't matched the other American pastimes.
Beckham was wildly cheered by many of the same diehard Galaxy supporters who booed him three years ago after his loans to AC Milan and an injury-riddled start to his Galaxy career. The Home Depot Center souvenir stands were loaded with Beckham shirts, including one that said "Take Me With You!"
Beckham has been in outstanding form for the past two years, patrolling the Galaxy's midfield and launching his usual sharp setup passes. He played aggressively for Los Angeles until the end, diving into the box and nearly converting a long pass for a goal in the 85th minute.
These two franchises have combined to win eight of the last 12 MLS titles, dating back to the Dynamo's days in San Jose. Houston seems stuck as a supporting player in the Galaxy's story, although the departures of Beckham and maybe Donovan will trigger big offseason changes in Los Angeles.
After winning the title last year on a Beckham-to-Keane-to-Donovan beauty of a goal, Los Angeles nearly had another storybook goal in the 13th minute when Beckham launched a long, high pass to a sprinting Keane, who slipped behind the defense and centered it perfectly for Donovan.
But he inexplicably pushed his shot inches wide of the post, leaving him with both hands on his head while the stadium released the usual post-goal confetti anyway.
The Dynamo improved their pressure late in the first half, and Adam Moffat's long pass eventually set up Carr's impressive near-post goal past Josh Saunders.
Carr leaped the corner flag in celebration of a rare score for the forward, a Bay Area native who joined the Dynamo last season and managed just four goals this year.
With Keane and Beckham leading the second-half charge, the Galaxy finally broke through when Gonzalez stuck around the box after a failed setpiece and managed to bounce a looping header past Hall. Gonzalez was MLS' top defender last year, and his late return from injury this season sparked the Galaxy's late-season surge.
Ricardo Clark was then called for a handball in the box in the 65th minute after an extended defensive scramble by the Dynamo. Donovan squatted down to prepare for his penalty kick before burying it in a back corner.
Houston frantically pressed for an equalizer in the final minutes, but Saunders and his defense repeatedly denied the Dynamo. After Hall wrapped his hand around Keane's thigh to stop a chance in the box, Keane confidently buried his sixth goal of a spectacular six-game postseason run in the Irish national team captain's first full MLS season.