Conor Casey also scored early for the Union (3-2-2), who led 3-1 at halftime. It was Philadelphia's first victory in four matches. Lionard Pajoy scored early in the second half to help United (1-5-1) back into the game.
Perry Kitchen also scored to help D.C. score multiple goals for the first time this season, even though it lost its fourth straight.
United has now lost three straight at RFK after having a 17-match home unbeaten run snapped in a 2-1 defeat against Columbus on March 23.
Pajoy scored his second goal of the season, and United's fourth in all, 2 minutes after halftime when he reached Daniel Woolard's cross and headed it past goalkeeper Zac MacMath from close range.
United then pressed for a tying goal, coming closest when Brandon McDonald's shot deflected off Philadelphia's Keon Daniel and just over the crossbar in the 64th minute.
But D.C. had few clear chances after that, and Daniel could've put it out of reach with a low strike if not for Hamid's reflex save in the 88th minute.
McInerney put Philadelphia up in the 7th minute when he reached Conor Casey's through ball, pulled away from D.C.'s Dejan Jakovic and McDonald, and finished inside the right post.
Casey struck four minutes later when he reached Danny Cruz's cross from the right and scored from the edge of the penalty area.
D.C. responded in the 17th minute when Kitchen scored on a nice cutback pass from Dwayne De Rosario.
But McInerney struck again for his sixth goal of the season in the 26th minute after reaching Sheanon Williams' throw-in that Amobi Okugo redirected with a header.