Catcher Wilson Ramos is mobbed by teammates after poking a groundrule double over Pirates right fielder Gregory Polanco to drive in Bryce Harper with the winning run. (Greg Fiume/Getty Images)

The ball flew off Wilson Ramos’s bat, and he knew where it was headed, just not sure where it would land. Pittsburgh Pirates right fielder Gregory Polanco raced back, jumped and then stopped. The ball bounced once and over the wall into the home bullpen at Nationals Park. Bullpen coach Matt LeCroy and reliever Drew Storen threw their arms in the air.

Bryce Harper, however, didn’t know where the ball was. He tagged up at second base, which he had reached after a wild pitch following his walk to lead off the ninth inning, then took off for third at breakneck speed. Only when he saw teammates stream out of the dugout did he realize Ramos’s hit had bounced over the fence for a ground-rule double that sealed a 4-3 comeback victory, the Nationals’ fifth straight win.

“That was close, but I hit the ball well,” Ramos said with a smile afterward.

Teammates mobbed Ramos in the infield, and Ian Desmond dumped Gatorade on them to celebrate a dramatic comeback. After being blanked for seven innings, the Nationals’ offense finally awoke with a three-run eighth powered by the red-hot Adam LaRoche’s game-tying, two-run home run with two outs. Ramos completed the come-from-behind victory an inning later, a full recovery from an inconsistent start by Gio Gonzalez.

The Nationals’ fifth walk-off victory of the season maintained their six-game lead in the National League East over the Atlanta Braves. Their five-game winning streak matches their season best.

Bryce Harper rounds third on his way home with the winning run as Washington captures its fifth straight. (Greg Fiume/Getty Images)

“When you’re on a streak, when you’ve got a little lead in the division, it’s easier to go relax and play and not get too uptight late in games, regardless if you’re down or not,” LaRoche said.

The Nationals were in a 3-0 hole by the third inning thanks to Gonzalez’s continued command struggles. He struck out seven but walked two and gave up three runs on seven hits. He needed 102 pitches to complete five innings.

Gonzalez was replaced in the sixth inning by Craig Stammen, whose three powerhouse innings gave the Nationals a chance to come back against the Pirates’ bullpen. Against Pittsburgh starter Jeff Locke, they could do little. Locke gave up only four hits in 52 / 3 scoreless innings.

The Nationals got two men on against the left-handed Locke in the fifth inning thanks to singles by Desmond and Ramos. But Danny Espinosa, who was starting because of his ability to hit left-handers, struck out on five pitches. Pinch hitter Scott Hairston, who also does well against southpaws, struck out on three pitches to end the threat.

“Shoot, we go from 21 / 2 hours of having pretty much no momentum — nothing really going that whole game,” LaRoche said, “to all of it coming at once.”

The Nationals’ rally in the eighth began against one of the best relievers in the league. Pinch hitter Michael A. Taylor drew a leadoff walk against left-hander Tony Watson, an all-star who entered with a 1.40 ERA. Taylor drew a six-pitch walk by laying off some close inside pitches.

Denard Span then laced a single to right field that allowed the speedy Taylor to race to third base. Kevin Frandsen slapped a bloop RBI single to right that allowed Taylor to score the Nationals’ first run.

The Post Sports Live crew overanalyzes Bryce Harper's motivation in walking through the Braves' "A" logo at home plate at Turner Field. (Post Sports Live/The Washington Post)

“This team is relentless. No matter if we’re eight runs down, guys still grind out at-bats,” Frandsen said. “Three-nothing game, it’s still with our type of offense, one swing can get you back in it.”

The inning’s energy was nearly sapped when Anthony Rendon hit a hard grounder at shortstop Josh Harrison, who started a double play. With two outs, up came LaRoche, the Nationals’ hottest hitter. Watson’s second pitch was a 94-mph sinker low and inside, where the Pirates had successfully attacked LaRoche all night.

LaRoche got under this one and drilled it into the home bullpen for a crowd-awakening home run that tied the game. Storen caught the ball as he warmed up on the bullpen mound. After a slumping July, it was LaRoche’s fifth home run in 10 games.

“When Rochey hit that bomb, that place was going nuts,” Frandsen said. Added Harper: “Being able to do that against a tough lefty was unbelievable.”

The sellout crowd of 41,880 kept roaring after LaRoche went down the dugout steps, hoping to lure him back for a curtain call. But just as LaRoche got back to the top step of the dugout and tipped his helmet to the crowd, the cheering stopped.

“Shoot, I didn’t know what was going on,” LaRoche said with a smile. “Teammates down there. [My son] Drake’s down there. And guys are pushing me up on the top spot. I still don’t know what happened. I take it I was a little late getting out there?”

After clawing back from three runs down, the Nationals knew the game had swung in their favor. Harper led off the ninth with a six-pitch walk, laying off pitches just off both edges of the strike zone. He took second on Justin Wilson’s wild pitch. Ramos, who grounded into a double play in his previous at-bat, wanted to move Harper to third base and fouled off two pitches.

Then Wilson fired a 96-mph fastball on the outer edge, and Ramos hit the ball toward right field. Ramos had a better view of the hit and was slower out of the batter’s box. He held his right fist up high as he cruised toward second. Harper, on the other hand, tore around the bases.

“I was still rolling,” Harper said. “I didn’t care. I had no clue if it was over the fence or if it was off the wall or Polanco had to get on it. I was just trying to roll as fast as I could. Once I saw Frandsen and them all running to the plate, I saw it hopped over the fence.”

Teammates crowded around Ramos. Some slapped his head. Others jumped on his back. Desmond dumped Gatorade on Ramos, which the game’s hero enjoyed.

“That was an amazing day,” he said. “I’m excited for this moment right now. We’re winning right now . . . five straight games. That’s good for the team. The most important thing [Saturday], the team never put their head down. We fight the whole game.”