ST. LOUIS — Clayton Kershaw couldn’t hold a two-run lead in a ballpark that’s been rough on him. The Los Angeles Dodgers won despite a so-so start from their ace lefty, who’d been virtually untouchable for a long stretch entering the All-Star break.

Adrian Gonzalez hit a tiebreaking single in the ninth inning off St. Louis Cardinals closer Trevor Rosenthal one at-bat after Hanley Ramirez was struck on the left hand, and the Dodgers salvaged the finale of a three-game series with a 4-3 victory on Sunday night.

“Your first emotion is to hit a home run and stand at home plate,” Gonzalez said. “But then you tell yourself you’ve got to stay within yourself.”

The Dodgers pulled into a virtual tie for first place with San Francisco in the NL West even though Kershaw was less than dominant. He’d been 8-0 with an 0.74 ERA his previous eight starts.

“It was a struggle,” said Kershaw. “I didn’t have a great idea where the ball was going for most of the night and I left some balls up.”

Yasiel Puig did not play after getting hit by a pitch on the left hand a day earlier and Ramirez was taken out — also after getting struck on the left hand. Ramirez was hit twice for the first time in his career.

Initial X-rays were negative on Ramirez, and both he and Puig were scheduled for a second round of X-rays Monday in Pittsburgh.

Gonzalez leads the National League with 38 road RBIs. He missed a chance earlier, flying out with the bases loaded to end the fourth. J.P Howell (2-3) got the last out in the eighth and Kenley Jansen finished for his 28th save in 31 chances.

Rosenthal (1-5) struggled pitching on the third consecutive day after earning saves the first two games. Peter Bourjos’ two-run homer off Kershaw tied it in the sixth.

“I think it was a flat breaking ball,” Bourjos said. “It was a mistake and fortunately I didn’t miss it.”

Cardinals manager Mike Matheny went to Rosenthal in a tie game because he had been “hesitant” to use setup man Pat Neshek a third straight time. Neshek also pitched in the All-Star Game, and Matheny said Rosenthal felt fine.

Kershaw gave up three runs in seven innings, the first time he allowed three runs since May 28, and needed 31 pitches to escape the sixth — an inning keyed by Matt Carpenter’s 11-pitch walk. He lost his previous four starts in St. Louis, the last two in the NLCS, and is 2-3 with a 3.68 ERA in seven regular-season starts overall at Busch Stadium.

Manager Don Mattingly said before the game that he had no doubt that bitterness lingered from Game 6 last fall when Kershaw was tagged for seven runs in four innings and the Dodgers were eliminated.

Kershaw was booed before flying out to end the sixth, a byproduct of dueling hit batsmen two innings earlier. Both benches were warned after St. Louis starter Carlos Martinez drilled Hanley Ramirez in the shoulder and Matt Holliday was plunked by Kershaw leading off the bottom half.

“I’m not going to talk about that, but I have a ton of respect for Matt Holliday,” Kershaw said. “He’s a great player and plays the game the right way, so that’s all I’m going to say about that.”

Matt Kemp and Andre Ethier had consecutive two-out RBI singles in the third to put the Dodgers up 3-1.

The highlight of the Dodgers’ fruitless fourth was Kershaw’s first career stolen base — his first attempt, too. Kershaw was running on a 1-1 pitch in the dirt and took second without a play with two outs.

Shelby Miller had made 50 consecutive starts over two seasons before entering in the sixth, and he was taken out after the first two Dodgers reached in the seventh. Coming out of the All-Star break, Miller was moved to the bullpen with off-days permitting the Cardinals to temporarily go with a four-man rotation, and after the game Matheny said Lance Lynn (11-6, 3.13) will go on regular rest Wednesday.

NOTES: The Cardinals have a day off Monday before beginning a two-game interleague series against the Rays. Ace Adam Wainwright (12-4, 1.83) is set for Tuesday against Jake Odorizzi (5-8, 4.01). ... Hyun-Jin Ryu (10-5, 3.44) starts for the Dodgers Monday against the Pittsburgh Pirates and Edinson Volquez (8-6, 3.65). Ryu is 6-2 with a 2.75 ERA on the road and 7-2 with a 2.88 ERA in nine starts against the NL Central. ... Kemp made an outstanding diving catch in left to rob Matt Adams of a bloop hit in the sixth.