David Beckham made his second appearance of the season, entering in the 53rd minute for the Galaxy (15-5-5), who maintained their three-point lead over second-place Real Salt Lake in the Western Conference and overall Major League Soccer standings. Before returning to play last week in a victory over Columbus, Beckham had been out of action since March 14, when he tore his left Achilles' tendon while playing for AC Milan on loan.
"He's ahead of schedule," Galaxy coach Bruce Arena said. "Our goal is to get him completely match fit by playoff time."
Andy Najar scored for D.C. United (5-17-3), which has lost eight of its past 10.
Donovan scored the winning goal in the 86th minute, heading Tristan Bowen's right-wing cross into the upper-right corner of the net. In the 81st minute, Donovan tied it on 14-yard shot after stealing the ball from defender Dejan Jakovic and drawing goalkeeper Troy Perkins away from the net.
Donovan said the Galaxy's poor play for most of the game motivated him to take charge.
"We didn't play well at all," Donovan said. "At the end of the day, there weren't very many places where we could say, 'we won that matchup.' When that happens, I take it upon myself to be more aggressive.
"To win the game is pretty remarkable. To be honest, I would've been ecstatic to get out of it with a point."
Donovan added that other factors motivated him.
"I wanted to make a statement," Donovan said. "I told myself before the game that I want to make sure we finish on top of the league and I want to be the MVP again."
Galaxy goalkeeper Donovan Ricketts kept D.C. United from moving ahead in the 85th minute by blocking Branko Boskovic's 13-yard shot off a breakaway.
"It's not always good enough to play hard," United interim coach Ben Olsen said. "We've got to be smart. We've got to be clinical and we've got to get cutthroat when we have the chances to do so."
The 17-year-old Najar opened the scoring in the 60th minute, sending a loose ball inside the right post from 12 yards.
Galaxy defender Omar Gonzalez will be suspended for Friday night's game against New York after receiving a yellow card in the 39th minute.