Barcelona, who used 23 players, won the first game of its three-game tour with goals by Pedro Rodriguez and Jeffren Suarez, but Beckham stole the show with his goal.
The crowd -- which was almost 30 percent more than the combined total for MLS's six weekend games -- was largely pro-Barca and booed Beckham continuously, though they cheered after his brilliant strike from 25 yards into the top corner, to goalie Jose Manuel Pinto's right, in the 45th minute.
"As soon as I hit it, I knew it was going in," Beckham said. "It's like a golfer. When you hit a golf ball. When you hit the sweet spot, you know where it's going. As soon as I was given the free kick I knew that I had a chance because it was in a good position. I knew if I got it on target, I would have a chance and lucky enough I did."
Beckham didn't seem to be concerned with the reception from the Rose Bowl crowd.
"There's going to be the odd reaction from a minority of people," Beckham said. "But 95 percent, 97 percent of the fans have been incredible."
MLS Commissioner Don Garber put a positive spin on the odd sound of the hometown star being booed, saying the fact that fans booed showed they cared.
"The opposite of love is not hate," he said. "It is indifference."
Garber added that he didn't agree with the way Galaxy fans have treated Beckham since his return to Los Angeles.
"We need to start to put all this behind us," he said.
Beckham said he remained committed to the Galaxy.
"I am contracted to the Galaxy and the MLS and I will be here next year," he said.
Aug. 1 in Pasadena, Calif.
Los Angeles Galaxy 1 Barcelona 2. Goals: Pedro 11, Jeffren 67; Beckham 45.
Los Angeles -- Saunders, DeLaGarza, Gonzalez, Sanneh (Berhalter 46), Dunivant (Griffin 84), Donovan, Beckham (Magee 87), Birchall (Klein 46), Miglioranzi (Kovalenko 66), Lewis (Jordan 77), Kirovski (Gordon 46; Patterson 88).
Barcelona -- Pinto (Valdes 46), Marc Muniesa (Puyol 46), Maxwell (Xavi 46), Marquez (Adriano Henrique 30; Gerard Pique 60), Daniel Alves (Gudjohnsen 46), Keita (Andreu Fontas 46), Toure (Henry 46), Dos Santos (Busquets 46), Messi (Jeffren, 46), Bojan (Abidal 46), Pedro (Victor, 46).
Referee: Baldomero Toledo