MIAMI -- Stephen Strasburg overcame a shaky start to earn his first victory in nearly a month.
"I knew if I kept the game close we could bust it open," Strasburg said.
Strasburg (7-9) struck out seven and also hit a batter, threw a wild pitch and had two run-scoring balks. It was his first win since Aug. 11 against Philadelphia.
"Stras should have been able to go further but he was a little out of sorts today," Nationals manager Davey Johnson said.
Rafael Soriano pitched the ninth for his 39th save in 45 chances.
"I like the way our lineup is swinging the bat," Johnson said.
Justin Ruggiano had three of the Marlins' six hits.
Jacob Turner (3-6) allowed five runs in four innings.
"We know we have to pitch and play almost perfect to win and we weren't able to do that," Marlins manager Mike Redmond said.
Ramos hit a solo homer in the second.
"I got a fast ball and I was able to get all of it," Ramos said.
The Marlins responded in the bottom half with three runs as Strasburg was erratic.
Strasburg gave up two hits, walked two and balked twice. After his second balk, he retired 10 in a row.
"Obviously, it can go two ways and you can let something like (the balks) affect you the next inning, but the way we've been swinging the bats I didn't want to do that," Strasburg said.
Zimmerman hit his 20th homer in the third. He has five homers in his last six games and has hit home runs in back-to-back games for the first time since hitting in three straight from Sept. 7-10, 2012.
Desmond tied the game at 3 with an RBI double.
The Nationals regained the lead in the fifth on an RBI single by Ramos ending Turner's outing.
"Obviously the team, in order to get the lead, is battling and then to give it right back is just frustrating," Turner said.
Anthony Rendon hit an RBI triple for a 5-3 advantage later in the fifth and Desmond's RBI triple to deep center field pushed the lead to 6-3 in the sixth.
Miami got a run back in the sixth on a pinch-hit RBI single by Greg Dobbs.
Marlins RF Giancarlo Stanton (foot) was held out of the lineup and was not available to pinch hit. "It felt the same as it did yesterday," Stanton said. ... Span is hitting .397 (31 for 78) during his hitting streak. ... The Nationals will start LHP Gio Gonzalez (9-6, 3.49 ERA) on Monday night in New York against Mets RHP Carlos Torres (3-3, 2.89). ... Miami will begin a series with Atlanta on Monday. The Braves will start RHP Kris Medlen (12-12, 3.48) against Marlins RHP Henderson Alvarez (3-3, 3.95).