Philadelphia (9-15-6) snapped a four-game home winless streak and pulled with three points back of sixth-place Montreal for the final playoff position in the Eastern Conference.
Houston (9-12-8) remained six points out of the final postseason spot in the Western Conference.
Barnetta scored in the third minute off an assist from Sebastien Le Toux. Le Toux came down the right side and crossed to Barnetta, who beat one defender and slapped the ball by goalkeeper Tyler Deric and into the back of the net.
C.J. Sapong matched a career best with his ninth goal of the season in the 63rd minute. Fabinho and Barnetta assisted on the goal.
The Union snapped a six-game winless streak against the Dynamo.