McNamara's goal was set up by a precision pass through the goal area from Tajon Buchanan. McNamara tapped in the feed with his right foot before being taken down by a couple of sliding defenders and clutching his right knee.
Jon Bell also netted his first tally of the season in the 78th minute and Gustavo Bou scored his third of the season in the 27th minute for New England. Revolution goalkeeper Matt Turner made seven saves.
Eastern Conference-leading New England has gone 5-1-1 since the start of May.
Thiago Andrade scored in the 55th minute of his New York City FC and MLS debut after signing with the team in April. Ismael Tajouri-Shradi logged his third goal of the year in the 85th minute while keeper Sean Johnson stopped just two of five shots.
New York City FC has scored at least once in 19 consecutive league matches (including playoffs) -- one shy of the club record set from March to July 2017.
Bell's header on a cross from Carles Gil in the 78th minute put New England up 2-1. However, the lead was short-lived as Tajouri-Shradi finished off a corner kick to equalize three minutes before McNamara's winner.
Andrade entered as a sub shortly after halftime and equalized at 1-1 for New York City FC. Andrade corralled a feed from Maximiliano Moralez at the top of the goal area, took a couple steps to his right and fired a right-footed shot off the right post and in past a diving Turner.
DeJuan Jones' feed across the box midway through the first half was headed up into the air and out to the penalty arc, where Bou unleashed a right-footed volley that split two defenders and snuck past Johnson into the lower left corner.