After the Nats rallied for three in the bottom of the fifth inning, Matt Williams turned to the bullpen.
Blake Treinen took over in the sixth, with switch hitter Chase Headley, right-hander Jose Pirela and left-hander Stephen Drew due up.
Treinen, who'd struggled vs left-handed hitters this season, (.351 BAA), gave up a two-out single to left field by Drew before he struck out Garrett Jones to end an 11-pitch inning, and Wilson Ramos tied it up with a solo blast to left in the home-half of the frame.
With switch-hitter Carlos Beltran, left-hander Brett Gardner and right-hander Chris Young lined up in the seventh, Williams sent Treinen back out and the hard-throwing right-hander retired the side in order on seven pitches, striking Young out with a filthy 0-2 slider to end the frame.
"We had A.J. [Cole] up as well," Williams said when asked after the game about the decision to go with Treinen in the sixth.
"If it stays at 6-2 we're going to use A.J. and go long, but if we got to 6-5 then Blake was going to be in the game, that's why he was hot. So he gives us a couple of innings and allows us to stem the tide and try to get back in it."
Williams talked about the sinker-balling right-hander improving against left-handers with more experience.
"The more and more lefties he faces the better command he's got of the sinker," the Nats' skipper explained.
"Threw some good sliders down and in to lefties tonight. Got CY on a couple of sliders. So, pitched really well and he's got the ability to go out there and do that. Early on he didn't have command against the lefty and the ball would sail off the plate, but he's made that adjustment and he's pitching well."
After Treinen, Matt Thornton, Aaron Barrett, Drew Storen and Matt Grace combined for four scoreless over which the Yankees had just one hit.
In the bottom of the tenth inning, after five scoreless from the Nats' 'pen, Ryan Zimmerman hit his walk-off blast for the 8-6 win.
"Great job," Williams said of his relievers' work. "Yeah. Great job by everybody. In a game like that, we get back in it and we were a little limited with Tanner [Roark] tonight because of his last outing, so we tried to mix and match as best we could. The fact that we got back into it is a credit to the offense. Getting back into that game, it's easy to pack tents and say it's not our night, but they don't do that."
The Nationals fell behind early on Wednesday night as well with the Yankees scoring two in the top of the first, but Ian Desmond in the first, and Tyler Moore in the fourth, hit solo home runs to tie it up at 2-2 and Jordan Zimmermann came through with six scoreless after which the Nationals rallied for the go-ahead run on an RBI single by Denard Span.
Matt Grace issued two-out walks to switch-hitter Mark Teixeira and left-handed catcher Brian McCann, but stranded both runners when Headley grounded into a force at second.
Drew Storen came out for the ninth and earned his 12th save of the season with a scoreless 15-pitch frame.
In back-to-back wins, the Nationals' relief corps limited the Yankees to two hits in seven scoreless.
"It's impressive," Williams said. "They've got a veteran club that's got power. [Grace] did a nice job tonight. Of course, their numbers left-handed are really good, so if we had an opportunity over the last couple of nights to get the guys on the other side of the plate, Headley, Beltran, then we wanted to do that, and Grace did a really night job tonight. And, of course, Drew pitched well in the ninth."
Williams was asked about his confidence in Grace, and his willingness to use the 26-year-old rookie in close games and tight spots.
"I just think he understands where to throw the baseball," Williams said.
"Tonight he wasn't throwing it exactly where he wanted to, but he made pitches when he had to as well. So, the ball moves a lot. His history says that he throws strikes down in the strike zone, and if we get in a situation like that against the proper guys, then we feel comfortable with him going out there in that opportunity and getting a ground ball, which he did tonight, multiple times, so he's pitched really well for us."
Through 13 games, Grace is (2-0) with a 2.53 ERA, a 3.12 FIP, six walks (5.06 BB/9) and nine Ks (7.59 K/9) in 10 ⅔ IP, over which opposing hitters have a .310/.396/.317 line.
The Nationals' bullpen as a whole has the 6th lowest ERA in the NL (3.16), 6th lowest FIP (3.43), fifth best left on base percentage (76.0% LOB%) and sixth-lowest BAA (.237).