NYCFC followed up a 2-0 victory at conference-leading D.C. by generating plenty of chances in a physical match that featured a combined 28 fouls and seven yellow cards
Castellanos scored his second goal of the season and third in 14 career games by teaming up with Heber.
Castellanos made it 1-0 by breaking past a defender into the middle of the box as Heber made a curling pass beyond the back line and through the box. Castellanos slid to finish off the play with a soft right-footed shot that eluded the diving attempt of Chicago keeper David Ousted.
NYCFC also improved to 2-0-2 in their last four games, on a night when Alexandru Mitrita sat out with an ankle injury, resulting in the 29th different starting lineup in 30 games under coach Domnec Torrent.
NYCFC later lost Ronald Matarrita (calf) in the 31st minute.
Goalkeeper Sean Johnson recorded his 57th career shutout without making a save, as Chicago had few quality scoring chances. The Fire registered six shots and none on target.
Ousted made two saves, as the Fire saw a four-game unbeaten streak halted.
After NYCFC went ahead, Chicago nearly scored four minutes later. The Fire were ruled to be offsides, and replays also showed that Nemanja Nikolic pushed the ball into the net with his hands while colliding with Johnson.
The Fire missed a chance in the 35th minute when Djordje Mihailovic's right-footed shot from outside the box sailed wide to the left of the net.
NYCFC missed an opportunity to get a second goal right before halftime, when Sweat's left-footed shot from the left side of the box missed wide to the right.
The Fire appeared to tie it on an easy tap-in by C.J. Sapong in the 48th minute, but Mihailovic was ruled to be offside and the goal was quickly disallowed.
NYCFC had a golden opportunity to get their second goal in the opening moments of second-half stoppage time, but Ousted stopped Maximiliano Moralez on a penalty kick.
NYCFC hang on for 2nd consecutive victory
After failing to register a win in their first six games of the season, NYCFC made it back-to-back victories with a 1-0 win over Chicago.
Valentin Castellanos strikes first for NYCFC
Major League Soccer: Valentin Castellanos (9') NYCFC 1-0 Chicago Fire