The city must pay $46,000 so a 20-year-old foster “child” can undergo male-to-female sex-change surgery, a judge has ruled.

It will be at least the fourth time the Administration for Children’s Services has paid for that kind of operation.

In the case of the current plaintiff — identified only as D.F. — the ACS must foot the bill for full genital “reassignment” and “facial feminization, tracheal shaving, breast augmentation and laser hair removal,” Manhattan Supreme Court Justice Peter Moulton ordered.

“Once she ages out of foster care [at age 21], petitioner’s chances of raising the money necessary to pay for these procedures appear to be nil,” the judge wrote, noting there is high prejudice against transgender people.

The judge wrote that D.F. is estranged from her family and has no high- school diploma.

“Certainly for the near future, her inability to pay for the procedures is clear,” Moulton wrote, slamming the city for being “arbitrary and capricious” in denying the funding.

The ACS had argued that D.F. was a poor candidate for a sex change because she is repeatedly absent from her group home and often misses medical appointments, making her unlikely to be conscientious in her postoperative care.

But the judge countered that D.F. had been found to be a good candidate by two psychiatrists and a psychologist at her group homes and clinics and the surgeon who would perform the sex change.

“Payment by ACS for necessary medical procedures may be a transgendered youth’s only chance to achieve congruence between her gender identity and her physical appearance,” the judge wrote.

A Law Department spokesperson said the city “will abide by the court’s ruling and provide the requested services.”