North Korea slapped the US with a $2 million bill for the hospital care of Otto Warmbier — forcing an American official to sign a pledge to fork over the money before being allowed to fly the comatose student back home from Pyongyang in 2017, according to a new report.

The US envoy sent to retrieve the University of Virginia student from the rogue regime signed an agreement to pay the bill on instructions passed down from President Trump, two people familiar with the situation told the Washington Post on condition of anonymity.

The invoice ended up at the Treasury Department, where it remained unpaid throughout 2017, the sources said. It was unclear whether Team Trump ultimately paid the bill or whether it came up in the run-up to the president’s two summits with Kim Jong Un.

The White House declined to comment to the newspaper about the bill, which was not previously disclosed by US or North Korean officials.

“We do not comment on hostage negotiations, which is why they have been so successful during this administration,” White House press secretary Sarah Huckabee Sanders wrote in an email to the New York Post.

Warmbier was arrested in January 2016 for allegedly stealing a propaganda poster while he was visiting Pyongyang with other Americans on a tour.

In March 2016, the 21-year-old fell into a coma for unknown reasons after being sentenced to 15 years of hard labor. He was released after 17 months.

The Trump administration arranged Warmbier’s transfer out of North Korea, but he died about a week later after falling into a vegetative state.

Pyongyang claimed he had fallen into a coma after contracting botulism and being given a sleeping pill — but he reportedly was subjected to a severe beating. Doctors in the US said he had suffered severe brain damage, but they weren’t sure what led to it.

Warmbier’s father, Fred, said he had never been told about the hospital bill, adding that it sounded like a “ransom” for his son, who late last year the dad said was “on his deathbed” when he returned.

News about Otto’s condition in North Korea sparked a frantic effort led by Joseph Yun, then the State Department’s point man on North Korea, to get the young man home.

Yun and a physician flew on a medical evacuation plane to Pyongyang, where they were taken to the Friendship Hospital, which only treats foreigners, and found Warmbier lying unresponsive and with a feeding tube in his nose.

Dr. Michael Flueckiger examined Warmbier, asked two local doctors about his care and then began talks to free him, the Washington Post reported.

“I didn’t realize what a negotiation it was going to be to secure his release,” said Flueckiger, medical director of Phoenix Air Group, an aviation company based in Cartersville, Georgia.

North Korean officials asked Flueckiger to write a report about his findings.

“It was my impression that if I did not give them a document that I could sign off on, that would cause problems,” he told the paper, adding that it was “evident” that Warmbier had received “really good care” in the hospital.

The doctors had done “state-of-the-art resuscitation” to revive him after he suffered a catastrophic cardiovascular collapse, Flueckiger said.

“Would I have lied to get him out of there? Maybe I would have,” he said. “But I didn’t have to answer that question.”

But Yun was placed in a tricky spot when the officials handed him the hefty bill — insisting he sign an agreement to pay it before they would allow him to take Warmbier home, the sources told the news outlet.

Yun informed then-Secretary of State Rex Tillerson, who then called Trump, according to the Washington Post.

They directed their envoy to sign the slip of paper agreeing that he would pay the $2 million, the two sources said.

A State Department spokesman and Yun, who retired last year, declined to comment to the paper. Tillerson, the Treasury Department and North Korea’s New York-based envoy responsible for US affairs did not respond to requests for comment.

After signing the documentation, Yun and Flueckiger returned Warmbier to his parents in Cincinnati, where he died six days later.

They requested that an autopsy not be performed.

The Warmbiers sued Pyongyang over their son’s death and requested $1.05 billion in punitive damages and about $46 million for the family’s suffering.

In December, Judge Beryl A. Howell of the US District Court in the District of Columbia awarded them $501 million in damages — money that they will likely never see.

Howell said it was “appropriate to punish and deter North Korea” for the “torture, hostage taking and extrajudicial killing of Otto Warmbier.”

Trump has said he believes Kim did not know about the student’s treatment.

“I don’t believe he would have allowed that to happen,” Trump said in Vietnam in February after his second summit with Kim.

The president said he spoke to Kim about Warmbier’s death and that Kim “feels badly about it.”

“He tells me he didn’t know about it, and I take him at his word,” Trump said at the time.