Anthony Rendon's ninth-inning single down the left-field line scored Bryce Harper as the Nationals walked off the D-backs, 3-2, at Nationals Park.
The win was the ninth in a row for the Nationals. Arizona has dropped its last five games.
"They've got it rolling and they overtook us again," D-backs manager Kirk Gibson said.
Harper opened the ninth against Evan Marshall with a single to center, and one out later, a single to center by Kevin Frandsen moved Harper to third, from where he scored when Rendon's grounder got past a diving Cliff Pennington at third.
"It's definitely a game of inches," Marshall said of Rendon's grounder. "The game plan was to go in there and attack them and try to force a ball on the ground, a double play or at least get the guy in a rundown. [Rendon] worked his hands inside the ball and kept it fair and just right up the line."
The win was Washington's fourth walk-off in its last five games, and second in this series.
"It's a little stressful," said Rendon. "I have some gray [in my hair] coming in now. But it's good to be on the winning side of these walk-offs. As long as we get a 'W,' it's a good time."
The Nats took a 1-0 lead in the second inning, when second baseman Aaron Hill had trouble getting the ball out of his glove on a potential double-play ball that would have ended the inning.
Combine that with Hill just missing Frandsen's ground-ball single up the middle in the ninth, and it added up to frustration for the veteran infielder.
"I should have made all the plays," Hill said. "The first one, it was unfortunate I couldn't get it out of my glove. The last one, honestly, I thought I was there, but it was hit a little harder than I thought. I should have made that play, as well. It was just one of those games where they were kind of picking on me. That's my job to stop it. But I'm beating myself up a little bit, because I know I should have made those plays. It's too bad."
Back-to-back doubles to open the sixth by Asdrubal Cabrera and Jayson Werth gave the Nats a 2-0 lead.
Those were the only two runs allowed by D-backs starter Trevor Cahill. The right-hander, who found himself back in Class A ball earlier this year trying to save his career, tossed 6 1/3 solid innings, scattering six hits and four walks while striking out five.
"Cahill was great," Gibson said.
It was the fifth straight quality outing for Cahill, who is showing that the team might be able to count on him to be a part of the rotation in 2015.
"I felt a lot better," Cahill said. "I know I had a couple of walks early on and then late, but that was probably the best I've felt, the best stretch I've had in a while, those middle innings. After the first two innings, I feel like I was able to settle down. A walk here and a walk there, I'd like to get those out of the way, but fortunately I was able to pitch around all but one."
Cahill struck out five, while the D-backs were unable to do much offensively against Washington starter Tanner Roark.
The right-hander held the D-backs scoreless while allowing five hits before departing after seven innings having thrown 99 pitches.
The Nats turned to setup man Tyler Clippard, and for the second time in the series, he was unable to hold onto a lead.
Pinch-hitter Jordan Pacheco greeted Clippard by drawing a walk, and Ender Inciarte followed with a home run to right field to tie the game at 2.
"Ender is turning into a real good player," Gibson said. "He's worked hard every day at all aspects of his game, and he's just applying it within the competition. It was just a fastball moving in on him, just kept his hands in, didn't try to do too much, good contact."