Nationals pitcher Livan Rodriguez has a word with Ted Barrett during the third inning. (Nick Wass/Associated Press)

The Washington Nationals managed to put a scare into the Arizona Diamondbacks, but only at the very end of Wednesday night’s game. The zeros piled up again until the Nationals had one out left. With back-to-back homers, they ended Daniel Hudson’s complete-game bid one out short. They forced the Diamondbacks to bring in their closer.

The thrill dissolved quickly into a 4-2 loss, with as little force as the Nationals had mustered over the previous two nights. The Nationals’ offense had rendered another strong starting pitching performance — this time by Livan Hernandez — a moot point. They avoided their 14th shutout of the season and second in two games when Laynce Nix and Jonny Gomes, both in the lineup because of Jayson Werth’s groin strain, hit back-to-back home runs.

The sudden spasm ended, though, after Wilson Ramos popped up, the only batter J.J. Putz faced. It could have mattered far more had reliever Henry Rodriguez not surrendered a two-run single in the eighth. Manager Davey Johnson pulled Hernandez with the bases loaded and called on Rodriguez, his most powerful and most erratic reliever. Rodriguez promptly yielded a two-RBI single to Miguel Montero, which stretched the Diamondbacks’ lead from two to four.

Over the past two days, the Nationals are 0 for 13 with runners in scoring position and have stranded 14 base runners, a combination of poor timely hitting and rotten luck. In the eighth inning, Ian Desmond’s double put two runners in scoring position with one out. Rick Ankiel hit a rocket directly at first baseman Lyle Overbay for the second out. Ryan Zimmerman hit a chopper up the middle, and the crowd started cheering until shortstop John McDonald made a running snag, spun and fired a one-hop throw to beat Zimmerman by a split second.

The Nationals’ biggest problem, though, was Hudson. He struck out six and walked none. After Michael Morse and Danny Espinosa hit consecutive singles to lead off the second inning, Hudson retired 17 of the next 18 batters he faced, a streak snapped when Nix doubled in the seventh inning.

The Nationals nearly dealt for Hudson, a 24-year-old right-hander who throws 95 mph, at last year’s trade deadline.

They reportedly could have sent Adam Dunn to the White Sox for him. Instead, the Diamondbacks traded Edwin Jackson for him, and the Nationals turned Dunn into two compensatory draft picks, which turned into Alex Meyer and Brian Goodwin (at a cost of $5 million).

Hernandez pitched well enough to win, allowing only two runs while on the mound in 71 / 3 innings as he threw 68 of 94 pitches for strikes.

Justin Upton, who walked to the plate in the fourth inning 1 for 12 in his career against Hernandez, started the Diamondbacks’ first rally with a one-out single to right. With two outs, Chris Young ripped a hanging curveball, perhaps Hernandez’s worst pitch of the night, to the warning track in left field.

The ball caromed off the fence and right to Gomes in left, a perfect hop. As Gomes grabbed the ball, he turned back to the infield and, looking at Upton run toward third, dropped the ball. Arizona third base coach Matt Williams turned his stop sign into a windmill, and Upton scored.

Gomes’s miscue was made moot one batter later, when Overbay rolled a single to right field, just past Michael Morse’s dive. Young scored easily, putting the Nationals down 2-0.

The Nationals would not score until the game almost ended, until they had posted 21 consecutive scoreless innings. They gave themselves a chance, but it came too late.