The Union (12-7-4, 40 points) notched their second straight win and improved to 3-3-1 in their past seven matches following a nine-match unbeaten streak from April 22 through June 3.
Martinez and Donovan scored their goals off brilliant sequences to help Philadelphia run its winning streak over NYCFC to five games, including postseason matchups.
Martinez struck in the 23rd shortly after a NYCFC miscue near the Philadelphia net.
Sullivan moved the ball down the left side and sent a cross to Martinez. As he slipped by NYCFC defender Tayvon Gray, Martinez finished off his second career MLS goal by sending a right-footed shot to the bottom left corner.
Donovan netted the eventual game-winner in the 81st minute when he gained possession near the box and slipped past Gray along the left side. After New York goalkeeper Luis Barraza came out of the net, Donovan easily tucked the ball into the open net for his first career MLS goal.
Five minutes after Donovan scored, Andres Jasson scored for NYCFC, sending his own rebound into the net after his attempt was blocked. Jasson's blocked attempt occurred two minutes after he hit the left post.
Philadelphia goalie Andre Blake made two saves in his return to the MLS after missing five matches to play for Jamaica in the CONCACAF Gold Cup. He capped his 221st career appearance by making a diving save on Gabriel Pereira five minutes into stoppage time as the Union moved to 17-1-2 in their past 20 home matches.
Barraza made one save but NYCFC (5-8-11, 26 points) saw its nine-match (1-1-7) unbeaten streak halted. NYCFC also dropped to 1-6-8 in its past 15 MLS matches.