Housing Secretary Ben Carson on Friday gave City Hall until Jan. 31 to make a deal with federal prosecutors on how to rescue the scandal-rocked New York City Housing Authority — threatening a federal takeover if the deadline isn’t met.

“Please be advised that if an arrangement acceptable to [HUD] regarding the future of the New York City Housing Authority is not reached on or before January 31, 2019 I intend to declare a substantial default with respect to NYCHA,” Carson wrote to Stanley Brezenoff, NYCHA’s interim board chairman.

Carson’s threatened declaration would lay the legal groundwork for a receivership or other drastic federal action if city officials can’t strike a deal, though his letter never explicitly uses the word.

An accompanying press release from HUD said the federal agency would like to keep “local control of day-to-day operations” in New York, suggesting officials in Washington remain reticent about pulling the trigger.

Carson’s statement did not mention the bevy of proposals rolled out by Mayor Bill de Blasio this week, which were part of a coordinated effort to head off the receivership threat.

In court papers filed late Friday, City Hall and Manhattan federal prosecutors echoed Carson’s deadline and asked Judge William Pauley to give them another 45 days to continue the negotiations over the authority’s future.

“We are in the middle of productive conversations with Secretary Carson and the U.S. Attorney to improve the quality of life for the 400,000 New Yorkers who call NYCHA home,” de Blasio said in a statement. “We all agree that the best outcome relies upon the City and federal government working together, and we look forward to continuing these discussions.”

The 12-page filing also claims that NYCHA has made new progress in complying with federal lead regulations, but admitted “[i]t is clear that NYCHA still has work to do to ensure that lead safe work practices are fully and consistently being followed.”

The cascade of developments late Friday night comes one month after Pauley nixed a settlement negotiated between City Hall and federal prosecutors in Manhattan. That deal would have imposed new federal oversight on NYCHA and injected $2.2 billion to help rescue its crumbling buildings — saying the deal didn’t go far enough.

Pauley also demanded HUD take a bigger role in any NYCHA rescue.

His decision injected new uncertainty into a deal that both sides thought was done, turning once two-way negotiations into more complicated three-sided talks, sources told The Post. It also opened the door for a potential federal takeover.

Officials and housing experts have long discounted the possibility of a receivership, because no one seemingly wants it.

“Nobody from the federal government wants the responsibility,” said a person close to the negotiations. “Nobody from the city wants the scarlet letter of a total federal takeover.”

That’s a position shared by even longtime critics of NYCHA.

“Carson kind of gets the ‘if you break it, you own it,’” said Judith Goldiner, a longtime attorney with Legal Aid, which is suing NYCHA over the miserable conditions many tenants are living in. “The Mayor is just getting slammed about this every day and if HUD takes it over, it will be Carson getting slammed every day.”

She added: “And who wants to be receiver with no money?”

The person close to the negotiations indicated two of the major hang-ups include securing additional federal money to fix NYCHA’s crumbling buildings and the scope of the expanded federal supervision — which have both long been sticking points.

A de Blasio rep declined to comment on the talks.

The receivership would be similar to a corporation filing for bankruptcy. It would empower either a judge or HUD to take over NYCHA’s management, clean out the existing bureaucracy and renegotiate contracts with unions and suppliers.

However, HUD’s track record with receiverships is, at best, mixed.

“While housing authorities under [HUD] receiverships have also made improvements, some continued to demonstrate a significant problem with housing units in very poor physical condition,” the federal government’s watchdog agency, the General Accounting Office, found when it examined the 11 authorities HUD has taken over in recent years.

It determined that receiverships run by judges fared better.

“The four housing authorities under judicial receiverships generally have continued to demonstrate strong performance; performance scores have improved and have generally remained high.”

But NYCHA’s orgy of scandal has left residents desperate.

Officials mounted a years-long effort to cover up dangerous conditions in public housing; lied for years about conducting mandatory lead inspections before eventually revealing 1,160 children who lived in NYCHA tested positive for exposure; failed to abate widespread mold and rodent infestations; struggled to keep the heat on during the winter season; and were rocked by salacious allegations of on-the-clock sex parties.

As the outrages piled up, so did the bills.

The authority revealed this summer it would need $32 billion over the next five years to bring its 325 complexes, which house more than 400,000 New Yorkers, back to a state of good repair. The bill is expected to grow to $40 billion by 2027.

Brezenoff, appointed to NYCHA’s board last year, compared running the authority to managing a “triage” operation.

Under heavy fire, the de Blasio administration began to take the threat of a receivership seriously in the days before the filing, rolling out a spate of announcements and circulating talking points among allies that bashed the idea of putting NYCHA in the hands of the feds.

De Blasio unveiled a new deal with the Teamsters that trades pay raises for more flexible work schedules, meaning NYCHA housing developments will be cleaned and staffed on weekends for the first time in decades.

And his administration finally released new details about a plan that aims to finance $24 billion in repairs over a decade — a dramatic bump from the originally available $8 billion, though the authority will remain well short of its needs.