Tanner Roark delivers a pitch during the fifth inning in Miami. (Rob Foldy/Getty Images)

Scott Hairston hadn’t had an at-bat in five days when he came to the plate Wednesday to lead off the eighth inning of a tie game . He would get only one at-bat as a pinch hitter, one of the most difficult jobs in baseball. The Washington Nationals had scored only one run over the previous 19 innings. He needed to get on base.

“My timing has been on and off all year, but I just wanted to focus on the middle of the field,” he said.

Hairston, however, was facing a left-hander, the type of pitcher on which he has built his career. He worked the count in his favor, then ripped a tailing outside change-up to the gap in left field for a double, barely beating the throw to second. The leadoff hit sparked a scoring outburst that helped the Nationals come to life late, avoiding a sweep at the hands of the Miami Marlins with a 4-3 win.

Denard Span followed Hairston with a bunt single, and Jayson Werth drove in the go-ahead run with a sacrifice fly. Ian Desmond’s double gave the Nationals two important insurance runs to help preserve another strong start by Tanner Roark.

The Nationals’ three-run eighth inning helped them withstand Drew Storen’s shaky two-run ninth. He notched his first save when Rafael Soriano was given two days off because of a recent heavy workload. After giving up a solo home run to Giancarlo Stanton and a run-scoring double to Adeiny Hechavarria, Storen pitched out of a two-on, two-out jam.

The Post Sports Live crew debates whether the Nationals should make a move at Thursday's trade deadline given Ryan Zimmerman's hamstring injury. (Post Sports Live/The Washington Post)

The win gave the Nationals a one-game lead in the National League East over the Atlanta Braves, who played late Wednesday night in Los Angeles. The Nationals finished a nine-game trip 5-4.

“We battled some stuff,” Desmond said. “We kind of endured. It was definitely a long road trip.”

The Nationals could return home optimistic after Roark continued his remarkable season with seven strong innings. Jordan Valdespin’s home run in the fourth was the only blemish.

“After the first inning, I felt like I got locked in and just stayed through the ball better and finished the pitches and trusted [catcher Wilson Ramos] back there,” Roark said.

His pitch count already at 100, Roark took the mound for the seventh inning. He got two outs — a flyout and strikeout — on five pitches. With Ross Detwiler warming in the bullpen, Roark gave up a single to Hechavarria before striking out Jeff Mathis on four pitches.

Roark’s start marked the sixth straight game a Nationals starter fired seven innings and allowed two runs or less, a team record.

Nationals starters have allowed only six runs over the past 42 innings, good for a sparkling 1.29 ERA. Roark has been just as dominant alone. In each of his past four starts, he has fired seven innings and allowed just one run.

“Those guys have been carrying us all year,” Storen said. “And recently they’ve been even better.”

The Nationals snapped a 14-inning scoreless streak with a run in the first. But after Anthony Rendon’s RBI double, the Nationals produced only three base runners over the next six innings.

Hairston’s at-bat — only his 49th of the season — sparked the eighth-inning tiebreaking rally. The team’s scouting report noted that Marlins starter Brad Hand’s pitches tailed away in the strike zone.

“I was looking for a fastball away. Although he threw me a change-up, it had a little tail to it,” Hairston said. “My mind-set was taking it back up through the middle. I was able to find a hole and able to get on base for Denard, who did his thing. And the rest of the crew followed through.”

Hairston has “been hitting lefties for his whole career pretty well,” Span said. “I feel like he was the X-factor. He got us going.”

Pinch runner Nate McLouth took over for Hairston at third base, and then Span stole second. Against right-handed reliever A.J. Ramos, Werth lifted a ball deep enough to left to score McLouth and give the Nationals a 2-1 lead.

Adam LaRoche then drew a walk and stole second base, a key play that put two men in scoring position for Desmond, who ripped a double to left to put the Nationals up 4-1.

“It’s a tough time for some of us, but you’ve got to keep grinding and doing the small things,” Desmond said. “That’s what we were able to do.”

Storen came in for the ninth and gave up a home run on his second pitch. He got two outs before yielding a single and then a soft RBI double just past LaRoche. He then walked pinch hitter Jarrod Saltalamacchia before getting a groundout to end it.

“Ugly,” he said. “But got it done. That’s really the main thing. It’s about winning the game and getting the save.”