A worker was killed and another was seriously injured — and remained trapped for hours — when a Midtown building being demolished to make way for a luxury hotel caved in Friday, authorities said.

There were 19 workers inside the eight-story building at 25 W. 38th St. when it collapsed at 10:28 a.m., sources said.

First responders bolstered the building’s basement with improvised shoring to prevent a further collapse before attempting to free the trapped man.

The injured worker, who was not identified, was pinned at the hip beneath a V-shaped mass of bricks and wooden beams as his rescuers labored to free him.

The FDNY erected a makeshift canopy to shield the man from bricks that continued to rain down on him throughout the three-hour ordeal.

He remained conscious but quiet during the rescue.

He was taken to Bellevue Hospital in serious but stable condition, and may have broken his legs.

His dead colleague also remained in the unstable building for several hours as rescuers prepared for the delicate work of retrieving his body.

He was found upright against a dumpster, his head pinned to the container by a large wooden joist.

He also was not named.

FDNY Captain Dominic Bertucci said rescuers used hand tools, air bags and jacks during the painstaking operation.

“I’m amazed he made it out, given the void he was in and the amount of debris above him. He’s very lucky,” he said.

Lt. Jonathan Negron said the victim squeezed rescuers’ fingers to let them know he was still alive.

“We were able to bring doctors in very close and give him an IV to control the pain,” Negron said. “We brought world-class medicine right to his side in that hole.”

All of the other workers were accounted and unharmed, sources said.

The names of the dead worker and the injured hardhat were not immediately released.

About 65 firefighters and 12 fire trucks rushed to the building, which contained scaffolding and netting.

The five-story building at 27 W. 38th St. also was being demolished.

“All I heard were people screaming and yelling. The two top floors collapsed and people are still trapped,” said a man who was working on the building next door at the time of the collapse.

“The ceiling caved in on the two top floors,” said the man, who did not want to give his name. “The guy in charge was screaming for everyone to get out.”

The building is the future site of the 27-story Aloft New York Midtown Hotel.

A complaint about excessive debris at the site was made on Aug. 25, sources said.

A source close to the investigation told The Post that construction debris was overloading a floor and caused the collapse.

“They (workers) were working on the fourth floor. They were taking the bricks down and stacking them on the floor. There is only so much (weight) the floor can take,” the source said.

A woman who answered the phone at Fortuna Realty Group, which owns the building, declined to comment other than saying Northeast Service Interiors holds the permit for the work at the site.

A woman who answered the phone at Northeast, of Maspeth, Queens, said the owners were at the site and unavailable for comment.

Metro Industrial Wrecking, a Long Island-based company that got a permit for full demolition in May, pulled out of the project recently after a dispute over money, Robert Bankston of Metro told The Post.

Fortuna said on its Web site that it acquired the building, between Fifth and Sixth avenues, in December 2012 and is planning the 27-story, 72,000-square-foot, 170-room boutique hotel.

Permits also were issued for work on electrical and sprinkler systems in the building.

Shane Nickens, 27, who was working in a building across the street, said he heard a loud crash.

“It sounded like a lot of scaffolding crashing together,” he said. “It was quick like a second. After that you heard a lot of sirens.”

Additional reporting by Melkorka Licea, Shawn Cohen, and Aaron Feis