The celebration is underway as Washington completes a sweep of Pittsburgh for its sixth straight win overall. (Katherine Frey/The Washington Post)

Sunday at Nationals Park was not for the faint of heart. The Washington Nationals put themselves in a hole thanks to sloppy defensive play. They took the lead late when the Pittsburgh Pirates made defensive miscues of their own. Struggling closer Rafael Soriano erased all of that with a three-run ninth-inning meltdown. But, only fittingly, Pirates closer Mark Melancon blew a save in the ninth, too, sending the game to extra innings. Four lead changes in all.

Got all that?

Finally, pinch hitter Scott Hairston brought an end to the wild game with a sacrifice fly in the 11th inning that scored Jayson Werth and sealed a 6-5 win. The second walk-off win in as many nights moved the Nationals to a season-high 16 games over .500 and six games ahead in the National League East over the Atlanta Braves, who also won Sunday night.

“Wasn’t the prettiest one, but it doesn’t have to be,” Manager Matt Williams said. “Guys fought hard.”

The Nationals won by mounting two late-game rallies. Werth, who entered the game in the ninth inning for his first action in a week while resting a balky right shoulder, hit a rocket double off the left field wall to lead off the 11th and spark the winning rally. Denard Span then battled reliever Brandon Cumpton for a hard-fought groundout to first that moved Werth to third. Hairston, the last non-catcher position player on the bench, lifted a high first-pitch fastball to left field to win the game.

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)

“We, as hitters, just had good at-bats leading up to the win,” Hairston said. “That’s what good teams do, and hopefully it will create more momentum moving forward.”

But how the Nationals avoided a gut-wrenching loss in the ninth inning after Soriano’s collapse was just as dramatic. A night after capping a late comeback with a walk-off win, the Nationals used the same magic to tie the game. Pinch hitter Werth drew a one-out walk. Span then battled Melancon for a tough eight-pitch at-bat that ended in a single to right, and Werth raced to third base.

Asdrubal Cabrera then hit a ball just past diving second baseman Neil Walker for the game-tying hit. Werth ran home, Cabrera clapped his hands at first base and the dugout erupted. Anthony Rendon nearly won the game when he drilled a ball to the gap in left-center field, but center fielder Starling Marte made a nifty diving catch to save the game for the Pirates. After Adam LaRoche struck out looking, the game went to extra innings.

The game, however, wouldn’t have reached that point had Soriano not faltered. The Nationals scored three runs in the seventh inning to take a 4-2 lead, and Soriano inherited that cushion when he took the mound to start the ninth. Sunday was his fourth appearance in five days. And from the start, he was off.

Soriano hit Marte, the first batter of the inning. He then gave up a hard-hit single to Travis Snider, a ball that hit off LaRoche’s glove and could have been a double play had the first baseman snagged it. Soriano then uncorked a wild pitch while facing Ike Davis that scored Marte. Pitching coach Steve McCatty came for a visit.

Soriano walked Davis and got a fielder’s choice groundout. Left-handed reliever Matt Thornton warmed up in the bullpen, and left-handed hitter Gregory Polanco was due up. Still ahead by one run with one out, Williams left Soriano in.

“He’s been our closer all year and done a great job for us,” Williams said. “Lately it hasn’t been what he wants, but we’ve got to give him a chance to get out of that inning.”

Soriano left a low 93-mph fastball over the plate, and Polanco smashed it to deep right-center field for a two-run double that blew the save. The crowd booed as Soriano trudged off the mound, replaced by Thornton.

“I try to make a good pitch,” Soriano said. “This guy be locked in, in the ninth. I know what I have to do. I try to make a good pitch. Nothing happen. Matt [Williams], he take a good decision. He take me out and put Matt [Thornton in].”

After a stellar first half of the season, Soriano hasn’t been the same in the second half. In his 11 appearances since the all-star break, Soriano has blown three saves and has a 7.71 ERA over 112 / 3 innings. Soriano has the experience and track record to survive rough patches, but now Williams faced questions about his closer’s job status.

“He’s been our closer all year, and I don’t see that changing as of right now,” Williams said.

Thornton escaped the inning for Soriano and, in extras, the Nationals turned to Ross Detwiler, who delivered two scoreless innings.

Long before then, the game featured a fine pitching matchup between Doug Fister and Edinson Volquez. Until a defensive collapse in the sixth inning, Fister mowed through the Pirates’ lineup. But the sloppy defense nearly undid the Nationals. Errors by Ian Desmond and Rendon helped hand the Pirates a 2-0 lead.

The damage could have been worse. After the second run scored on an infield single, Pedro Alvarez singled to right to load the bases with still nobody out. Even with the game slipping through his hands, Fister found a way to wriggle out somehow without allowing any more runs.

Leading 2-1 in the seventh, the Pirates returned the favor. With the bases loaded and only one out, first baseman Davis fired a wild throw home that allowed two runs to score, including Kevin Frandsen who alertly scored from second. Span then scored on the next play when third baseman Alvarez, who has a history of throwing problems, uncorked a bad throw on a fielder’s choice groundball that gave the Nationals a 4-2 lead.

This set the stage for the final innings of theater. When the Nationals had a two-run lead before Soriano’s collapse, Williams didn’t want to use Werth, who hadn’t swung a bat in a week until this weekend. With the Nationals trailing in the ninth, however, Werth was needed. Werth tested his shoulder in the indoor batting cages and felt he could contribute. And he did, scoring both the game-tying and game-winning runs to extend the longest winning streak of the season.

“I’ve been saying all along we were going to go on a run,” he said. “And this [is the] time of year where you can turn it on and separate a little bit. So hopefully we keep doing that.”