PITTSBURGH — The Dodgers couldn’t have asked for better timing, as Shohei Ohtani’s leadoff spot came back around.

In a game the Dodgers would go on to win 8-6 over the Pirates, they were clinging to a two-run lead in the top of the seventh inning against the Pirates on Thursday. With one out and runners on first and second, the Dodgers superstar, who had already reached base four times, was due up.

Instead, Santiago Espinal stepped up to the plate as a pinch-hitter.

Ohtani left the game with inflammation in his left knee, the Dodgers announced. They did not immediately offer an explanation for the injury.

Before leaving, Ohtani hit a solo home run — his second homer in as many games — a single and drew two walks.

It was an impressive performance, coming a day after he took on two-way duties. On the mound Wednesday, he allowed three earned runs in 6⅔ innings.

He’s been on an offensive tear. He entered Thursday with a .400 batting average and 1.207 OPS in his last 25 games — dating back to May 12, the day before manager Dave Roberts gave him two consecutive days off from hitting.

Earlier in the game Thursday, Dodgers starting pitcher Justin Wrobleski exited with a bruised right hamstring, the team said.

The fifth inning had already begun to spiral on him. After throwing four scoreless innings, he surrendered two solo home runs to Rafael Flores Jr. (the first of his major-league career) and Brandon Lowe.

Then Bryan Reynolds hit a line-drive comebacker off the inside of Wrobleski’s right leg. The ball ricocheted to the edge of the infield grass, where first baseman Freddie Freeman picked it up.

Wrobleski was already racing toward first base. But after turning to catch the throw, he missed the base and stumbled backward into Reynolds, who tripped over Wrobleski’s extended left foot.

Wrobleski limped away, and an athletic trainer followed him, circling back to the mound. But as he was setting up to throw a warm-up pitch, manager Dave Roberts came out to make a pitching change.

Wrobleski was charged with four runs in 4 ⅔ innings. He gave up six hits and a pair of walks.

The Dodgers bullpen bent but did not break, with the help of late-inning insurance runs from the offense. Right-hander Tanner Scott recorded the final four outs, striking out the side in the ninth.