The winner came one minute after Bastian Schweinsteiger tied the game for Chicago in second-half stoppage time.
Cory Burke scored two goals and Haris Medunjanin added one goal for the Union, who earned just their second road win of the season.
The Union had dropped four of five.
Nemanja Nikolic and Aleksandar Katai also scored for the Fire. It was their second straight defeat after a five-game unbeaten stretch.
In the 19th minute, Burke worked his way free to the left of the box but fired a bending shot just over the goal.
Chicago had a solid scoring chance in the 26th minute when midfielder Brandt Bronico took a shot from the top of the box but hit it a bit wide and high.
The Union took a 1-0 lead in the 31st minute on Medunjanin's second goal of the season and the fourth of his career. He dribbled through a pair of Fire defenders and scored into the corner of the net.
Katai nearly equalized in the 33rd minute but was denied with a save by Philadelphia goalkeeper Andre Blake.
Union defender Mark McKenzie took down Katai in the box in the 38th minute, and the referee whistled for a penalty kick.
Nikolic tied the game at one-all on the PK in the 39th minute. It was his ninth goal of the season.
Just before the third minute of first-half stoppage time ended, Burke headed home a cross from Fafa Picault for a 2-1 Philadelphia advantage.
In the 63rd minute, Nikolic made a run into the box and just missed finishing a cross with a sliding shot.
Katai tied the game at two-all in the 69th minute and joined Nikolic with nine goals apiece this season.
Philadelphia responded quickly as Burke put the Union back ahead 3-2 in the 73rd minute with his second goal of the game. Accam took the initial shot and Burke tapped home the rebound.
Chicago 3-4 Philadelphia: Accam punishes former club
Bastian Schweinsteiger scored late, but it was the former Chicago player David Accam that stole the show deep into stoppage time for Philadelphia.