New York officials overpaid nearly $5 million to a Manhattan hospital after a young Medicaid patient died — then demanded a “shocking’’ refund from the child’s family to fix their accounting error, new court papers show.

Merrick Lee was just 8 years old when he died in 2010 after a lifetime of struggling with an immune-deficiency order.

His parents, Korean immigrants who live in Syosset, LI, said a botched stomach X-ray at New York-Presbyterian Hospital in November 2003 left the then-17-month-old boy severely disabled — and in a hospital room nearly the rest of his life.

“He passed away five years ago. We lose our whole life,” Merrick’s father, Chi Young Lee, told The Post on Monday as his wife sobbed.

The family sued the hospital and won a $6 million settlement in April 2008.

As part of the deal, the hospital agreed to “assume full responsibility for any . . . [money] due to Medicaid in connection with [Merrick’s] . . . hospitalization,” according to court papers.

But officials with the city’s Human Resources Administration disregarded notices they received saying their agency did not have to pay the Medicaid bills — and unnecessarily shelled out millions of dollars to New York-Presbyterian.

When they realized their mistake, they went after the family.

In a recent ruling against the city, Manhattan Supreme Court Justice Alice Schlesinger noted that the HRA officials acknowledged they received notice of the settlement but simply “lost” the paperwork.

Calling the mix-up “negligent,” Schlesinger characterized the city’s refund demand to the Lees as a “shocking request for relief.”

The family’s lawyer, Andrew Kimler, added, “It’s really just a tragedy, and all this does is bring back the horrors.”

A spokesman for the HRA admitted, “Errors were made five years ago by all parties to this unfortunate situation.”

But the spokesman, David Neustadt, also blamed the state and the hospital, saying that New York-Presbyterian “was paid $4.8 million in state Medicaid money it was not owed.

“As the local social-service district, HRA is legally required to recover taxpayers’ money from the hospital for the state,” Neustadt said, adding, “We are no longer seeking to recover any funds” from the Lee family.