Dunn connected in the fifth after first baseman Chris Duncan dropped a foul pop that would have been the last out of the inning.
Martis (3-0) retired the first 14 hitters he faced before Yadier Molina grounded a single through the middle in the fifth. The right-hander, who had never gone more than 6 1-3 innings, struck out six and walked none in a 110-pitch effort.
Colby Rasmus hit his first career homer for St. Louis, which had won three straight games.
Ryan Zimmerman doubled in the first, extending his Nationals-record hitting streak to 21 games, the longest in the majors this season.