Nieves drove an 0-2 pitch from Chicago's Bob Howry (0-2) into the Washington bullpen in right field for the Nationals' second straight win after dropping 16 of 19 games.
Austin Kearns led off the ninth with a single off Howry. Kearns, who was hitless in his previous 14 at-bats, was held out of the starting lineup for the first time this season by manager Manny Acta. He entered the game in the eighth as a defensive replacement.
After Willie Harris struck out, Nieves, who entered in the seventh as part of a double switch, hit a drive to the opposite field, and Washington had its second win in its final at-bat of the season. Nieves, who started the season with Triple-A Columbus, connected in his 163rd big league at-bat.
Jon Rauch (2-0), Washington's fifth pitcher of the evening, worked a perfect ninth.
Chicago, the NL Central leaders, had won six of its previous seven.
Nick Johnson hit a two-run home run off Ryan Dempster into the second deck in right field in the first inning. It was the first home run to reach the second deck of Nationals Park since it opened this season.
The Cubs cut it to 2-1 in the third off Odalis Perez when the left-hander hit Reed Johnson with a pitch with one out. He scored on Ryan Theriot's double.
In the fifth Johnson led off with a single, advanced on a walk and moved to third on a fly before scoring on a fielder's choice.
Washington took a 3-2 lead in the sixth. Cristian Guzman reached on an error by first baseman Derrek Lee leading off. After Ryan Zimmerman singled and Johnson bounced into a double play with Guzman taking third, Lastings Milledge hit an RBI single to right.
Chicago tied the score at 3 in the eighth. Aramis Ramirez and Kosuke Fukodome led off with singles off Luis Ayala. They moved up to second and third on Mark DeRosa's sacrifice.