The Democratic-controlled House on Thursday approved a bipartisan $4.6 billion Senate-drafted measure to care for migrant refugees detained at the southern border — after House Speaker Nancy Pelosi backed off a competing proposal opposed by the President Trump.

The 305-102 vote capped a Washington skirmish in which staunch House liberals came out on the losing end in a battle with Trump, the GOP-controlled Senate and Democratic moderates.

The legislation would ease a cash crunch at federal agencies that care for migrants who have flocked over the border in huge numbers seeking asylum since Trump took office.

Final action came after Pelosi abandoned a plan to require more stringent care requirements for detained migrant families and children, many of whom have been held in harsh, overcrowded conditions.

House progressives were furious with Pelosi for caving to the GOP, but any bill that included their own demands stood little chance of becoming law, with Trump threatening a veto and Senate Majority Leader Mitch McConnell saying it would never get through the upper chamber.

Trump has indicated he would sign the bipartisan measure.

“A great job done by all!” Trump tweeted after the House vote from Japan, where he is attending the G-20 summit.

Pelosi earlier Thursday “reluctantly” did an about-face and said she would back the bipartisan Senate-passed border-aid bill.

“In order to get resources to the children fastest, we will reluctantly pass the Senate bill,” the California Democrat said in a statement.

Vivid and painful accounts of harsh, even dangerous conditions at badly overcrowded federal facilities that house and care for thousands of migrants added to the pressure to act.

Pelosi succeeded in passing a Democratic measure on Tuesday by a near party-line vote, but her efforts began to unravel with a decisive 84-8 Senate tally that undercut House efforts to win back add-ons aimed at guaranteeing improved treatment of migrants.

Vice President Mike Pence and Pelosi had an hour-long conversation on the legislation Thursday as the White House and Republicans kept pounding the message that the only way forward on the long-sought legislation was to pass the Senate bill.

The legislation contains more than $1 billion to shelter and feed migrants detained by the border patrol and almost $3 billion to care for unaccompanied migrant children who are turned over to the Department of Health and Human Services.

The Senate measure is not as strict in setting conditions on the delivery of funding to care for unaccompanied children and contains funding opposed by House Democrats to finance logistical support provided by the Pentagon and to ease a payroll pinch at Immigration and Customs ­Enforcement.

Pelosi was seeking provisions requiring more stringent care requirements for detained migrant families and children than the Senate package and other steps, but immediately had difficulty executing it.

Moderate Democrats pressed for immediate action on the Senate bill, undercutting her efforts.

The leaders of the House Progressive Caucus, which includes almost half of House Democrats, immediately issued a statement calling the Senate bill — which had the backing of Minority Leader Chuck Schumer — “entirely insufficient to protect vulnerable children in our care.”

But with Congress recessing for the July 4 holiday, House Democrats lacked the leverage to ­negotiate.

With AP