The United States government rescinded its controversial decision to revoke foreign student visas whose courses move online due to coronavirus, a federal judge said Tuesday.

The universities of Harvard and MIT -- with the support of a number of other institutions, teachers' unions and at least 18 US states -- had taken legal action against the move that US Immigration and Customs Enforcement (ICE) announced on July 6.

"The government has agreed to rescind" the decision as well as any implementation of the directive, Judge Allison Burroughs said in a brief hearing.

Harvard and MIT earlier this month had asked the court to block the order announced by ICE that students must leave the country if their classes are only online, or transfer to a school offering in-person tuition.

The measure was seen as a move by President Donald Trump's administration to put pressure on educational institutions that are adopting a cautious approach to reopening amid the global COVID-19 pandemic.

The universities say in their lawsuit that the order would harm students "immensely," both personally and financially.

It describes the order as "arbitrary and capricious" and says it threw US higher education "into chaos."

There were more than one million international students in the US for the 2018-19 academic year, according to the Institute of International Education (IIE).

The court gave no reason for the Trump administration's flip, and the president did not immediately react Tuesday.

"We are thrilled that the government backed down," said the University of Southern California in a statement.

"Our international students are a vital part of the USC community, and they deserve the right to continue their education without risk of deportation."

The Massachusetts Institute of Technology (MIT), shown here, along with Harvard asked a court to block an order by President Donald Trump's administration threatening the visas of foreign students whose entire courses have moved online
The Massachusetts Institute of Technology (MIT), shown here, along with Harvard asked a court to block an order by President Donald Trump's administration threatening the visas of foreign students whose entire courses have moved online GETTY IMAGES NORTH AMERICA / JOE RAEDLE

Most US colleges and universities have not yet announced their plans for the fall semester but Harvard has said all its classes for the 2020-21 academic year will be conducted online "with rare exceptions."

Some 40 percent of undergraduates will be allowed to return to campus, but their instruction will be conducted remotely.

It says packed classrooms endanger the health of students and teachers.

Trump has branded the decision "ridiculous" as he takes a bullish approach to reopening the country ahead of November's presidential vote, when he seeks reelection.

Despite the continued progression of coronavirus throughout the United States -- which has confirmed more than 3.4 million cases, with more than 136,000 deaths -- Trump has aggressively insisted that schools must open this fall.

The US president has threatened to withhold federal funding from schools that refuse to reopen and criticized guidelines from the US Centers for Disease Control for the safe reopening of educational institutions, saying they are too rigid and expensive.

Cracking down on immigration is one of Trump's key issues, and he has taken a particularly hard stance on foreigners since the health crisis began.

In June, he froze until 2021 the issuing of green cards -- which offer permanent US resident status -- and some work visas, particularly those used in the technology sector.

"Thankfully, this attack on students is over," said Andrea Flores, deputy director of immigration policy for the American Civil Liberties Union, following the ruling.

"But the administration will undoubtedly continue in its failure to protect the people in America by using the pandemic for its hateful agenda to dismantle our immigration system, rather than creating a coordinated response for the future of our nation."