Lionard Pajoy began the final scoring play by passing the ball with the back of his right foot to free Farfan in open space. Farfan's diagonal 17-yard shot off his right instep from the left side of the penalty area threaded between goalkeeper Josh Saunders and the right post.
"We're jelling a lot quicker," said defender Gabriel Farfan, who attributed that improvement to new coach John Hackworth.
"Hack's done a great job of organizing us, and I think it's showing," Farfan said. "Whether it's their creativity, their bite, their technical skills, I think everyone brings something to the table and it's finally coming together."
McInerney agreed regarding Hackworth's influence.
"Coach Hack taking over has just been a good change for us," McInerney said. "It's been a sense of relief."
McInerney put the Union ahead with seconds remaining in the first half by scoring his fourth goal in four games against league opponents and in the U.S. Open Cup.
Michael Farfan received a pass from Amobi Okugo and dribbled toward the right side of the penalty area before Galaxy defender David Junior Lopes forced him to cross the ball while flush against the end line.
McInerney deflected Farfan's cross with the back of his left heel. The ball rolled slowly toward the goal line and tapped the inside the left post before going in.
Los Angeles (6-10-2) tied the score in the 73d minute, as Chad Barrett slid to convert from 2 yards.
The Galaxy had three chances to take a lead in the first 11 minutes. But Carlos Valdes cleared Robbie Keane's 5-yard shot away from an open net in the fourth minute.
A minute later, goalkeeper Zac MacMath parried Hector Jimenez's 13-yard shot away. Then in the 11th minute, Keane's 4-yard shot toward an open net deflected off Sheanon Williams' right arm.
"Tonight was all about effort," McInerney said. "Every time L.A. got a chance, people were putting a body in front of the ball. The results haven't always been there, but the last three or four games, we've been playing like this."
The Galaxy's Omar Gonzalez, the MLS defender of the year in 2011, made his season debut and played the first half. Gonzalez tore the anterior cruciate ligament in his left knee in January while training with Germany's FC Nurnberg.
David Beckham, who leads the Galaxy with five assists, was suspended for the game after receiving a yellow card against San Jose on Saturday night.