SAN FRANCISCO -- After overpowering the San Francisco Giants with Yasiel Puig's triples one night and Clayton Kershaw's pitching the next, the Los Angeles Dodgers found a much more unconventional way of beating their rivals Sunday night.

They used the strikeout as an offensive weapon.

In fact, the Dodgers got positive results from two strikeouts in a three-run fifth inning, taking the lead for good en route to a 4-3 victory over the Giants and a three-game sweep in the matchup of the National League West's top two teams.

"It doesn't matter how you do it," Dodgers first baseman Adrian Gonzalez said. "The fact that we got the sweep in San Francisco, that's great. Especially against a team that handled us earlier this year."

Left-hander Hyun-Jin Ryu earned his 12th win and three Dodgers relievers combined for three innings of shutout ball as Los Angeles moved 1 1/2 games ahead of San Francisco after beginning the series 1 1/2 games back.

In losing for the 19th time in their past 25 home games, the Giants dropped into a tie with the Atlanta Braves atop the wild-card standings, a half-game ahead of the St. Louis Cardinals.

"It's going to be important we put this one behind us," Giants manager Bruce Bochy said. "We have to regroup. You have no choice in this game. You're going to stumble, and what's important is how we deal with this.

"L.A. played great. Sure, it's not fun getting swept here at home, but there's a lot of baseball left."

Shortstop Hanley Ramirez broke a 2-2 tie with an RBI single in the fifth, and left fielder Carl Crawford drove in the eventual winning run with a triple. The Dodgers went on to post a win that capped a 5-4 road trip, one that began with series defeats at St. Louis and Pittsburgh.

"You make enough of a statement by winning three games, but that's all it is," Dodgers manager Don Mattingly said. "You've got a lot of baseball to play. We're going to see these guys again. They're not going anywhere."

Ryu (12-5) gave up a solo home run to Giants catcher Buster Posey in the bottom of the sixth, then turned the ball over to the bullpen after the inning. He allowed three runs on six hits, walked one and struck out seven.

Left-hander J.P. Howell, right-hander Brian Wilson and closer Kenley Jansen held the one-run advantage from there, with Jansen striking out the side in the ninth to record his 30th save.

The Giants held 1-0 and 2-1 leads early, but the game flipped on first-time San Francisco starter Jake Peavy in the top of the fifth.

After a diving stop by Giants third baseman Pablo Sandoval denied Ryu a probable double to lead off the inning, things got crazy.

It began innocently enough when Dodgers second baseman Dee Gordon struck out on a Peavy curveball in the dirt. However, the pitch got away from Posey, allowing the speedy Gordon to reach base.

Puig followed with a walk, and both runners advanced on a wild pitch, Peavy's second of the inning.

With the Giants playing their infield back and willing to concede the tying run on a groundball, Peavy then struck out Gonzalez on another pitch that bounced. Posey managed to keep this one within 15 feet, but when he left the plate area to retrieve it and throw out Gonzalez at first, Gordon dashed home ahead of first baseman Adam Duvall's return throw to Peavy, tying the game at 2-2.

"I always think about it at third base, but I don't have the speed for it," Gonzalez said of Gordon's feat. "I'm glad he took advantage of it."

Gordon admitted he was just trying to make something happen with the Dodgers trailing by a run.

"It was on my own," he said. "I just wanted to help us win the game. That's what I was able to do.

"(I took off) as soon as (Posey) snapped his head (toward first base) and didn't look at me. I didn't think he could get me and Gonzo (Gonzalez). That's when I decided to go."

Mattingly labeled the mad dash the turning point in the game.

"Obviously Dee does things that nobody thinks about," he noted. "Guys like him and (Cincinnati's Billy) Hamilton, they're the only ones who know how fast they are. Dee knows his speed well, and over the years he's learned how to use it."

Ramirez then hit the next pitch into left field for an RBI single that scored Puig from second and gave Los Angeles a 3-2 lead. Crawford followed with a bloop triple down the right field line, and Ramirez came all the way around to make it a three-run inning and a 4-2 game.

Posey's two-out home run in the bottom of the inning got the Giants back within 4-3, but San Francisco managed only two baserunners in the last three innings, none of them advancing past first base.