Authorities say the 30-year-old man was discovered trapped inside the shaft behind the wall of a first-floor apartment on East 26th Street in Kips Bay just after midnight.
The man, who had just moved into the seven-story building, was hanging out with friends on the roof when he decided to climb into the air shaft.
Firefighters had to remove a wall to reach him after he got stuck. The rescue operation took 40 minutes.
The man was uninjured, but he was taken to Bellevue Hospital for evaluation.