AP photo by Marcio Jose Sanchez / Atlanta Braves outfielder Eddie Rosario watches his two-run homer during the seventh inning of Wednesday night's game against the host Los Angeles Dodgers.

LOS ANGELES — Justin Turner and AJ Pollock singled home the tying and go-ahead runs through the same infield hole in the eighth inning, and the Los Angeles Dodgers rallied past the Atlanta Braves 4-3 on Wednesday night to complete a three-game sweep.

The Dodgers got more good news after their game ended: The San Francisco Giants lost 5-2 to the Milwaukee Brewers. That gave Los Angeles sole possession of the National League West Division lead by a half-game over the rival Giants.

The reigning World Series champions hadn't been in first place since April 25. They are off Thursday, when the Giants finish their series with the Brewers, before beginning a pivotal showdown Friday in San Francisco.

The Dodgers staked Max Scherzer to an early 2-0 lead and he was dominating the Braves, who lead the NL East as they seek a fourth straight division title, when he left after 76 pitches because of a tight hamstring. The right-hander struck out nine batters and walked none in six innings.

"It was a no-brainer," Dodgers manager Dave Roberts said. "He knows his body better than anyone. He knows when to push himself and when to be smart."

Scherzer said he didn't injure his hamstring.

"Just knew it was tight," he explained. "From there, had to throttle down. Couldn't fully get on my back leg. Had to work around it."

Atlanta shortstop Dansby Swanson hit a tiebreaking solo home run — his 26th of the season — in the eighth, giving his team a 3-2 lead. He had been hitless in three at-bats against Scherzer.

"Everything he threw was on the edge," Swanson said. "He was mixing up his pitches well. It was like he was pitching in ways we haven't necessarily seen before. He was really, really good."

The Dodgers tied it at 3 on Turner's single in the hole between third and shortstop. That scored Trea Turner, who doubled and went to third on Max Muncy's groundout.

Corey Seager followed with a walk against Chris Martin (2-4), putting Justin Turner on second with two outs. Pollock singled through the same hole as Justin Turner, who scored for a 4-3 lead.

Phil Bickford (3-1) got one out for the win. Joe Kelly pitched the ninth to earn his fifth career save.

The Dodgers' Mookie Betts struck out four times for the second time this season.

The Braves lost their third in a row for the first time since a four-game skid from June 9-12. They also dropped their first road series since July 5-7 against the Pittsburgh Pirates, and have lost seven in a row and 10 of 11 at Dodger Stadium.

Atlanta's division lead dropped to two games over Philadelphia.

"We just didn't hit consistently enough to give ourselves a chance, but we pitched the ball pretty freaking great," Swanson said.

"There were a lot of good things from the series, and I feel like this was a really, really good experience for us because this is what it's going to be like for us come the end of the season and the playoffs. Just glad to go through it at the end of August and not October."

Brusdar Graterol followed Scherzer and gave up three straight hits, including a single by Travis d'Arnaud, who scored on Eddie Rosario's home run that tied it at 2 in the seventh.

Muncy slugged his 30th home run of the season in the first off Max Fried. It's the third time the first baseman has had 30 or more homers in a season. He also tripled in the third.

Austin Barnes homered leading off the third to make it 2-0.

Scherzer retired 11 in a row after giving up a single to Freddie Freeman in the first.

The Braves put the potential tying runs on base in the fifth with singles by Rosario and Ehire Adrianza, but in a Max vs. Max matchup, Fried struck out swinging against Scherzer to end the inning.

Fried retired seven straight before walking Trea Turner leading off the sixth. He moved up on Fried's wild pitch, but Justin Turner lined out to second to end the inning.

Braves second baseman Ozzie Albies felt better than expected a day after fouling a pitch off his left knee and being carried off the field, but he'll be evaluated again Thursday.

Atlanta opens a four-game series against the Colorado Rockies on Thursday in Denver.