Jayson Werth delivered the decisive blow, hitting the go-ahead double to cap a three-run rally in the eighth inning by Washington. (John McDonnell/The Washington Post)

Four outs away from being swept by an utterly depleted division rival, the Washington Nationals may have saved any dying hope for their season.

The Nationals topped the New York Mets, 6-5, before a national TV audience on Sunday thanks to a dramatic comeback in the eighth inning that was capped by Jayson Werth’s run-scoring double to right-center field.

The rally hinged on a crucial sacrifice bunt by Bryce Harper three batters into the inning. It was a curious move at the time, but Harper’s decision to move his teammates into scoring position helped the Nationals pull within 61 / 2 games of the Cincinnati Reds for the second wild-card spot.

Trailing 5-3 in the eighth, the Nationals changed the course of the entire contest — and perhaps their final 26 games. Scott Hairston led off the inning with a single off left-hander Scott Rice. Pinch hitter Denard Span, who has struggled against left-handers this season, entered with a 14-game hitting streak on the line. He smacked a single up the middle. This was the first clue to Werth that something special was at work.

“I didn’t even know he had that streak going on,” Werth said. “To extend [it] that like that, when that happened, I knew we had some magic working.”

Up came Harper with two runners on and no outs. Harper has struggled against left-handers as well this season. He had a slight limp earlier in the game, but both he and Manager Davey Johnson said later his left knee wasn’t bothering him. In this situation, Harper decided to trade an out for a base for each of his teammates. Johnson didn’t signal for the sacrifice attempt; Harper made the choice himself.

“You’ve got to get him over,” Harper said. “You don’t want ground into a double play or anything like that. Down 0-1, he actually hung me a curveball I probably could’ve drove, but I was lucky enough to get it down and get those guys over and get into a big inning.”

Harper’s bunt prevented the following hitter, Anthony Rendon, from hitting into a double play. Rendon’s groundball to shortstop Omar Quintanilla allowed Hairston to score and trim the deficit to 5-4. Ryan Zimmerman then hit a groundball up the middle toward Quintanilla, who gloved the ball but couldn’t get much on the difficult throw to first base. Span raced around the bases and beat first baseman Lucas Duda’s throw home. The Nationals had tied the game at 5. While curious at the time, the bunt proved vital.

“I wasn’t sure though because he took the first pitch,” Hairston said. “But it was the right play. It was definitely the right play in that situation. In that situation, you almost have to bunt. I know he’s hitting the ball well.”

Then Werth, one of the hottest hitters in baseball, provided the final blow in the comeback. He drilled the double that scored Zimmerman. After Zimmerman crossed home plate, he pumped his fist. The entire Nationals bench was at the railing of the dugout jumping and cheering, perhaps the most energy seen from this team all season.

“I was on the top step looking like I was about to go and tackle J-Dub and give him a hug,” Harper said. “I was so fired up and very happy that he got that knock. I think our whole dugout was ready to just run on the field and tell him congrats and it was awesome.”

The Nationals were given a chance to mount a comeback once Mets left-handed starter Jonathon Niese left the game with a leg injury in the sixth inning. Niese had allowed 10 hits, but nine of them were singles. He found a way to limit all those base runners to only two runs over 52 / 3 innings.

All game, the Nationals took shot after shot at the left-handed starter but couldn’t deliver the damaging punch. With a nearly all right-handed lineup, the exception being leadoff hitter Harper, they chipped away at the four runs allowed by Ross Ohlendorf over his laborious five innings.

Tyler Moore singled in Werth in the second inning. Hairston pulled the Nationals within one run with an RBI single in the fourth. Once Niese was out of the game, Wilson Ramos trimmed the deficit to 5-3 with an RBI single in the seventh off reliever Scott Atchison. Ramos’s hit proved important as reliever Ian Krol allowed a run in the top of the frame. This would set the stage for the dramatic eighth inning.

Johnson, who noticed Harper limping after his second at-bat, agreed with Harper’s decision to put down the bunt.

“As tough times as we’ve had with hitting with runners in scoring position, putting the tying run down there ain’t a bad idea,” Johnson said. “And with some pretty good hitters coming up behind him.”

He later added: “If we get swept, I’d be having nightmares on that bus ride to Philly. But there’s a lot of baseball left.”

And in the Nationals’ clubhouse, they believe there is still a chance.

“The rest of the way these games are going to be pretty much do or die games,” Werth said. “We’re gonna have to win. We’re gonna have to win every night. We’re gonna have a little wiggle room there but not a whole lot.

“I’ve been in this situation before. I know it can be done. I’ve been on teams that have done it. I believe. I got faith. We got a long hard road but I believe.”