Flames erupted at Trump Tower early Saturday evening, killing one resident of the luxury Midtown building, officials said.

The four-alarm blaze broke out on the 50th floor of the Fifth Avenue building at about 5:30 p.m., ­according to the FDNY.

President Trump tweeted at 6:42 p.m. that the fire was under control — and he used the occasion to boast about the building’s construction.

“Fire at Trump Tower is out. Very confined (well built building),” the president said. “Firemen (and women) did a great job. THANK YOU!”

The FDNY said the blaze actually was brought ­under control at 7:40 p.m.

Nearly 200 firefighters and 50 members of the FDNY’s Emergency Medical Service responded, officials said.

First responders performed CPR on resident Todd Brassner, 67, before he was rushed to Mount Sinai West Hospital, where he died.

There are no sprinklers in residential sections of the 58-story building, but they’re not required by law in structures of that age. Trump Tower opened in 1983.

“This is a very difficult fire as you can imagine,” FDNY Commissioner Daniel Nigro said.

“The apartment [where the blaze broke out] is quite large — we are 50 stories up — the rest of the building had a considerable amount of smoke.”

Nigro praised his firefighters.

“The apartment was virtually entirely on fire,” he said. “They pushed in heroically. They were knocking down the fire. They found one occupant of the apartment on the 50th floor.”

Lalitha Mason, a 36th-floor resident, said she was “terrified.”

“It was a very horrible experience . . . there was no evacuation system in place . . . we were at a loss of what to do. I almost fainted. I thought we would die,” she said.

“My husband is disabled and we were helpless. All we could do is put wet towels under the door and pray.”

Elevator service was knocked out, so resident Claudia Ospina, a Telemundo reporter, walked down 37 floors with her 19-month-old twins.

“We were afraid because I didn’t hear any alarm; I didn’t receive a call,” Ospina said.

She learned there was trouble only when she looked out her window.

“When I saw [firetrucks] I thought, ‘Oh, my God, this is the worst,’” Ospina said.

Four firefighters were hurt — two with burns. None sustained serious injuries, authorities said.

Additional reporting by Amanda Woods, Daniel McKnight and David K. Li