Tyler Moore rounds the bases after hitting a three-run home run in the eighth inning. (Justin K. Aller/Getty Images)

Bryce Harper sat in the Washington Nationals’ clubhouse, ejected before they had even taken the field. Three Pittsburgh Pirates occupied the bases, aided by another throwing error from Ryan Zimmerman. Gio Gonzalez stood on the mound, already trailing after the first pitch he threw soared over the fence and yet to record an out.

Faced with bleakness early Sunday afternoon, Gonzalez responded with calm. The Nationals used myriad contributions in a galvanizing, 6-2 victory at PNC Park that gave them a winning road trip and pushed them back to two games over .500. None of that, though, would have been possible if Gonzalez had not first escaped a horrific first inning and perhaps righted his own season in the process.

“A younger me would have probably spiraled out of control, tried to do too much,” Gonzalez said.

After the first four Pirates batters reached, Gonzalez retired 15 of the next 17 hitters he faced and lasted six innings, leaving with a one-run lead. Second baseman Danny Espinosa spearheaded an 11-hit outburst with three RBI and a two-run homer, and Tyler Moore’s three-run blast in the eighth provided breathing room for a bullpen that didn’t need it. Drew Storen, Tyler Clippard and Rafael Soriano all tossed scoreless innings.

The Nationals finished a road trip against two winning teams at 4-3, and their overall record stabilized at 17-15, only two games worse than the first-place Atlanta Braves. The Nationals have won four of the last five, and their offense finally came to life over the weekend. The brightest news Sunday may have been the resurgence of Gonzalez, who proved himself still a pitcher capable of turning disaster into a speed bump.

“I thought it said a lot about Gio,” Espinosa said. “He was in a place where a lot people could just give up. He battled right there. For me, that was turning the point. It was like, ‘Let’s go.’ ”

Gonzalez climbed the mound with a 5.34 ERA, which ranked in the bottom 10 of the National League. He was intent on rebounding from his four-inning, five-run debacle in Atlanta.The team’s best player already had been sent to the showers by crew chief John Hirschbeck, who took issue when Harper raised his arms to protest a third-strike check-swing call.

And then Gonzalez found himself trailing after he had thrown one pitch.

Gonzalez began with a 92-mph fastball over the plate and low. Starling Marte blasted it into the upper deck in left field. In his previous start, Gonzalez had yielded a leadoff home run to Andrelton Simmons. Now for the second straight start, he trailed 1-0 after a single batter.

It seemed things could not get worse, and then they did. Jordy Mercer ripped a double. Andrew McCutchen followed with a routine grounder to third base, the kind that allowed Zimmerman to throw on the run. His heave across the diamond tailed inside the baseline, too far for Adam LaRoche to keep his foot on the bag. Gaby Sanchez walked to load the bases with no outs.

Pitching coach Steve McCatty trudged to the mound, pausing a first inning from hell. He reminded Gonzalez to slow down.

As Gonzalez started below his standard this season, McCatty pinpointed a frequent mechanical mistake. When Gonzalez allowed base runners, he would speed up his delivery. He would drop his left arm, and his front shoulder would open too quickly, allowing hitters to see the ball more easily. Trouble begat trouble. Bad innings snowballed into start-wreckers.

“Sometimes when he gets hit, he rushes out there,” McCatty said. “That’s one of his problems.”

Even through his struggles this season, Gonzalez’s pitches remained invulnerable — opponents had hit .220 off him before Sunday. If any pitcher could wriggle out of a jam, it was Gonzalez, even in his diminished state.

“You had to make the adjustment quick,” Gonzalez said. “I was just trying to slow their game down.”

He struck out Russell Martin swinging at a change-up. He froze Michael McKenry with a 94-mph fastball. Brandon Inge rolled a grounder up the middle, and Ian Desmond ranged behind second base and flicked a sidearm throw to first.

“Unbelievable job,” LaRoche said. “He could have easily gone the other way.”

The Nationals immediately tied the score with a sac fly from Espinosa in the second. In the fourth, he gave them the lead with a mammoth two-run homer to left field off Pirates starter Wandy Rodriguez — a second consecutive left-handed opposing starter, which Espinosa said allowed him to find a groove with his right-handed swing.

Given a lead, Gonzalez protected it. After the first, Gonzalez allowed one run on three hits and one walk. His ERA dropped to 4.97, and his season had started to turn in the right direction.

“Gio’s not been as consistent as he was last year, and he hasn’t been hitting his spots. He hasn’t been getting all his pitches over,” Manager Davey Johnson said. “So it was good to see him bounce back.”

The Nationals put the finishing touches on in the eighth. Roger Bernadina, Harper’s replacement, sparked the Nationals’ game-breaking rally with a leadoff bunt single in the eighth, just his second hit of the year. A groundout moved Bernadina to second. Pirates Manager Clint Hurdle ordered Bryan Morris to intentionally walk LaRoche, who already had reached base eight times in the series, one week removed from an 0-for-26 drought.

“A week ago,” LaRoche said, “they don’t think twice that I’m getting pitched to.”

Hurdle wanted to face Moore, who had struck out in all three of his at-bats Sunday and six times in the series.

“It fires you up a little bit,” Moore said. “But you can’t blame them. I would have done the same thing.”

On Saturday, Moore had rebounded from two crucial strikeouts to smack the game-winning sac fly. Now he destroyed a two-strike, three-run homer to left field, pushing the Nationals’ lead to four.

“Sometimes, one at-bat like that can flip everything for a team,” Espinosa said. “It can get everything rolling.”

The Nationals could relax, something that seemed impossible when the day began. After Soriano recorded the last out, Gonzalez found Johnson in the dugout and shook his hand.

“He was the old Gio,” Johnson said. “All grins. I haven’t seen that grin in a long time, so that was a lot better.”