Bryce Harper continues his recent surge with a two-run single in the first inning that was preceded by a foul ball off the left fielder’s foot. (Jonathan Newton/The Washington Post)

July was a rough month for Adam LaRoche. Before the month started he had been one of the Washington Nationals’ best hitters, and then it all came crashing down. He hit .159 and mashed only one home run. All he needed was last month to end and August to begin.

Since the beginning of this month, LaRoche has been one of the team’s best hitters. The Nationals snuck by the Pittsburgh Pirates, 5-4, for their fourth straight win Friday for many reasons — Tanner Roark’s strong-enough start and a strong showing from the offense and bullpen, save for Rafael Soriano’s ninth inning — but LaRoche’s two hits proved crucial in the close game.

With Ryan Zimmerman out for perhaps another month with a hamstring strain and Jayson Werth recovering from his balky right shoulder, the Nationals’ offense can use all the help it can get from LaRoche and Co. LaRoche can be a streaky hitter, and when he gets hot, he can carry a lineup almost single-handedly. His continued August turnaround will be an important factor for the Nationals, who maintained their six-game lead over the Atlanta Braves in the National League East.

“He’s a big piece to our puzzle, to our team,” center fielder Denard Span said. “If he can get hot, it’s only going to make things better for us. He was so great for us early on in the year. When he gets hot, he’s dangerous.”

LaRoche is hitting .333 (17 for 51) with four home runs and nine RBI over his last 14 games. Last month, he drove in only 11 runs. With his help and a key two-run single by Bryce Harper, the Nationals produced just enough offense to withstand Soriano’s shaky inning in which he allowed three hits and a run.

Starter Tanner Roark labored through 5 2/3 innings but kept grinding to earn his 12th win of the season. (Jonathan Newton/The Washington Post)

“He’s got the job done for us all year,” Manager Matt Williams said of Soriano. “That’s three [days] in a row for him, so that’s a pretty heavy workload, but he got through it.”

With the way the Nationals manhandled Pirates starter Charlie Morton in the first three innings, the game seemed headed only in one direction. What looked like an easy win on a beautiful August night quickly turned into a close game thanks to a three-run fourth inning by the Pirates.

Roark had a 5-0 lead when he took the mound in the fourth. Neil Walker doubled to right field with one out. Roark then hung a slider to Starling Marte, who crushed it into the left field seats for a two-run home run.

“That’s the [pitch] I tried to make perfect,” Roark said. “And when you try to make pitches perfect, that’s what happens.”

Roark gave up one more run in the inning after Travis Snider walked and No. 8 hitter Pedro Alvarez smoked a fastball to deep right-center field for a double. Span fielded the ball on a hop at the warning track and whipped a throw to second baseman Asdrubal Cabrera, who spun and fired home.

Cabrera’s throw beat Snider to the plate by at least 15 feet. The ball hit the lip of the grass, however, and catcher Wilson Ramos couldn’t field it. The ball bounced off his left leg, and Snider slid in safely.

The Nationals’ lead was trimmed to 5-3, but Roark found a way to pitch into the sixth inning even on an off night.

The Post Sports Live crew debates what the odds are that the division-leading Baltimore Orioles and Washington Nationals meet in the World Series. (Post Sports Live/The Washington Post)

“The one thing about Tanner is that he wants to go nine innings every time he’s out there regardless of the situation,” LaRoche said. “You’d think he’s been playing for 10 years with the amount of confidence, and [he] just has a knack for keeping it together and keeping his cool. The guy doesn’t get flustered.”

After Roark allowed a two-out single in the sixth inning and his pitch count reached 107, Williams took the right-hander out of the game. Jerry Blevins came in for a lefty-on-lefty matchup against first baseman Ike Davis. Pirates Manager Clint Hurdle countered by sending up pinch hitter Gaby Sanchez, who grounded out to end the inning.

The Nationals gave Roark a big lead early when the first six batters reached in the first inning against Morton. Span led off with a single and then stole second base, but he was thrown out easily trying to steal third, a mistake that cost the Nationals a run.

Cabrera walked and Anthony Rendon singled to put runners on first and second with one out, and LaRoche drove in the first run with a single. Ian Desmond followed with a walk to load the bases for Harper.

While batting, Harper fouled a ball off his right foot and fell to the ground in pain. He got up slowly and took his time getting back in the batter’s box. He then sent the ninth pitch of the at-bat just over second baseman Walker’s head for a two-run single that gave the Nationals a 3-0 lead.

“We’ve been swinging the bat pretty dang well,” Harper said. “Being able to have a deep lineup like we do, we just go up there, take pitches, draw walks, make him have long innings, throw a lot of pitches, get him out of there early and get to their bullpen. That was huge.”

The Nationals finally chased Morton after the third inning when they hung two more runs on him. LaRoche’s RBI single just past the shortstop made it 4-0, and Ramos’s single up the middle scored another run. LaRoche’s second hit, when he made a conscious effort to hit the ball the opposite way, was the best sign of his improvement.

Drew Storen and Tyler Clippard each pitched a scoreless inning in relief, but Soriano injected drama into the ninth when he gave up a leadoff single and then two two-out singles. He managed to escape the inning by getting Josh Harrison to pop up in foul territory for the final out of the game.