The Union rebounded after their last game, a 2-1 loss to the New England Revolution, and improved to 8-5-7, good for 31 points.
It was the eighth shutout this season for Union goalkeeper Andre Blake.
NYCFC (9-6-4, 31 points) has been one of the hottest clubs in the league and had its six-game unbeaten streak (4-0-2) snapped.
In the 20th minute, the Union earned a free kick and Kai Wagner sent a strong ball through the box, resulting in a corner kick. The corner kick was cleared, however.
NYCFC controlled possession in the first half, but were whistled for a pair of yellow cards.
Philadelphia came out aggressive in the first five minutes of the second half yet couldn't come up with a shot on goal despite several crosses into the box.
NYCFC picked up a free kick in the 58th minute from the corner of the box and after the kick caromed off the wall, a shot deflected off a Union defender and out of bounds.
The Union went ahead 1-0 in the 67th minute when Bedoya ran into the box and headed Wagner's cross past Johnson. It was the first goal of the season for Bedoya.
Castellanos was taken out in the 77th minute, largely because he could have missed NYCFC's next game with one more yellow card. Castellanos has eight goals and six assists this season.
Anton Tinnerholm ripped a shot in the 90th minute, which ended up being a corner kick for NYCFC. But after the corner, the Union quickly cleared the ball.