A judicial flip-flop is causing chaos at the southern border.

US authorities shut down a bridge in El Paso, Texas, late Friday after a federal appeals court dealt a sharp blow to President Trump’s border-enforcement strategy — then suspended its order hours later.

A three-judge panel of the 9th Circuit Court of Appeals struck down a program that requires Central American migrants to wait outside the US while their asylum cases are pending.

More than 100 migrants stormed the Ciudad Juarez-El Paso border bridge as word of the ruling spread in the Mexican camps where at least 25,000 asylum-seekers are waiting, authorities said.

The Department of Justice credits the policy, known as “Remain in Mexico,” with a steep drop in border arrests, which have plunged 80 percent from their peak last May — but the American Civil Liberties Union has sued to end it, calling it ­“unspeakably cruel.”

The court put its ruling on hold in response to an emergency motion from the Trump administration, which said an end to the program “could prompt a rush on the southern border,” as happened briefly in El Paso.

DOJ officials have until Monday to file a response, and probably will appeal the case to the Supreme Court, which has ruled in the administration’s favor on other immigration cases.

The “Remain in Mexico” policy, also called Migrant Protection Protocols, aims to end so-called catch-and-release policies that allowed hundreds of thousands of illegal immigrants to live in the US while their asylum claims wended their way through the courts.

Critics have long contended that those rules encouraged economic migrants to claim asylum even when they have no hope of it being granted to them.

Under international law, asylum is meant for those facing deadly religious or political persecution in their home countries.

And Trump has frequently asserted that large numbers of those who apply for asylum never appear for their court dates in order to dodge deportation.

His policy of keeping migrants in Mexico instead has sent about 60,000 asylum-seekers south of the US border since it was instituted in January 2019, a DOJ official said.

With Post wires