WASHINGTON - Harvard University and the Massachusetts Institute of Technology sued the Trump administration Wednesday over an order that would require foreign students to take classes in person this fall, despite rising coronavirus caseloads that are complicating efforts by colleges and universities to offer in-person learning.

The lawsuit represented a swift response to an unexpected order issued this week by the federal government as universities rush to protect the status of thousands of foreign students. It also marks a new rift between Trump and education leaders over how to safely reopen schools in the midst of his reelection bid.

"We will pursue this case vigorously so that our international students - and international students at institutions across the country - can continue their studies without the threat of deportation," Harvard's president, Lawrence Bacow, told the university's community Wednesday.

On Monday, the federal Student and Exchange Visitor Program announced that visas would not be issued to students enrolled in schools that are fully online this fall. Under the rule, those students would be barred from entering the country. And to keep their visas, students already in the United States would need to leave the country or transfer to a school with in-person instruction.

The rule has not been published, but the guidance issued Monday stunned university officials and panicked students. Although foreign students had been required to take classes in person, the government offered schools and students flexibility this spring after the pandemic shut down most campuses. And it had said the new guidance would remain in effect for the duration of the emergency.

So as university officials worked to finalize fall plans, many assumed that their foreign students would be allowed into the country even if they were not in the classroom. With cases rising across the country, most colleges are at least prepared to switch to fully virtual instruction if needed. Others, including Harvard and the sprawling California State University System, have already announced plans to offer little to no in-person instruction.

Harvard has about 5,000 foreign students, and MIT has about 4,000. In their lawsuit, the universities say U.S. Immigration and Customs Enforcement's decision was designed to force universities to conduct in-person classes, part of a political strategy from the Trump administration to pressure schools, from kindergarten to graduate school, to fully reopen this fall, even as virus cases soar.

The lawsuit, filed in U.S. District Court in Massachusetts, seeks a temporary restraining order that would quickly stop the government from enforcing the policy. The schools say the rule violates the Administrative Procedure Act, which governs rulemaking by federal agencies.

The Department of Homeland Security did not immediately respond to requests for comment. Carissa Cutrell, a spokeswoman for ICE, said the agency "is unable to provide further comment due to pending litigation."

The lawsuit cites remarks from acting deputy secretary of homeland security Ken Cuccinelli on Tuesday, in which he said the directive "will . . . encourage schools to reopen."

The decision also reflects the administration's efforts to limit and reduce the presence of foreign students in the country, the lawsuit argues.

The Trump administration says the new policy will provide more flexibility for colleges and universities. Cuccinelli indicated Tuesday that foreign students could remain in the United States as long as they receive at least some face-to-face instruction.

Cuccinelli told CNN that the administration was seeking to "force" universities to offer in-person teaching. But he acknowledged that the administration wants to spur movement in that direction. "This is now setting the rules for one semester, which we'll finalize later this month that will, again, encourage schools to reopen," he said.

The ICE rule frightened foreign students, who worried that they risked deportation if their schools were not providing classes in person.

"That's horrifying - I couldn't sleep," said Mita Rawal, who's studying pharmacology at the University of Georgia. "It's not just me, it's my son, he goes to school here. If I had to pack up my bags and go to Nepal -" she said, and then trailed off.

She had already been through a tumultuous spring and summer, with a sudden need for a computer for her own studies and a secondhand laptop for her 5-year-old son's schooling, paid for with the help of an emergency grant from a nonprofit. Her dissertation was put on hold, and she was unable to travel home for the summer.

And then news broke from ICE. "I had not anticipated in my wildest dreams that I would be in this situation," she said.

Outraged faculty members are mobilizing to defend foreign students. Some are brainstorming ways to work around the administration’s policy, creating makeshift classes for foreign students.

Dana Fisher, a sociology professor at the University of Maryland, said she woke up Wednesday to 25 emails from terrified students. She had fielded more the day before. On Twitter, she offered an independent-study course to any student who needs to take an in-person class this semester. Dozens are interested, she said.

Sarah Parkinson, an assistant professor of political science and international studies at Johns Hopkins University, said there is talk among professors about holding improvised face-to-face sessions with anyone who might need them, to ensure that students do not get caught in a crackdown. Holding a class session in a park with a few students, sitting six feet apart, could be an option.

"It's not even a question. Of course you'd do it," Parkinson said.

The administration's policy prompted an array of higher education leaders to defend the ideals of international education and student exchange. Millions of students have come to the United States in the past century, they said, an extraordinary pipeline of talent that has promoted democracy around the world and helped build the U.S. economy.

MIT's president, Rafael Reif, told the school's community Wednesday: "Our international students now have many questions - about their visas, their health, their families and their ability to continue working toward an MIT degree. Unspoken, but unmistakable, is one more question: Am I welcome?

"At MIT, the answer, unequivocally, is yes." He wrote about his own memories of the anxiety of arriving in the United States to study, "excited to advance my education, but separated from my family by thousands of miles. I also know that welcoming the world's brightest, most talented and motivated students is an essential American strength."

For the past several years, according to the Institute of International Education, the United States has hosted a little more than 1 million foreign students. Fall typically heralds the arrival of a new group of more than a quarter-million. But educators worry the pandemic could lead to a sharp drop, slashing tuition revenue for colleges across the country. The administration's new policy adds to those concerns.

"The present efforts by American leadership to eliminate this truly successful, strategic asset of American economic and cultural leadership is a deeply misguided mistake," Michael Crow, president of Arizona State University, which has more than 10,000 foreign students, wrote in an email.

Matyás Kohout arrived in the United States from the Czech Republic wearing Converse sneakers covered in American flags. Coming from a formerly Communist country, where his parents had been unable to go to college, read Western literature or travel outside the country, the United States was a dream for him.

He even shared a birthday, he said: July 4.

He got a glimpse of fireworks as best he could from a window while quarantined this year. Two days later, he saw the news about visas. At first, he thought it was a mistake. When he realized it was true, he tried to figure out what would happen if George Washington University's law school moved to online classes partway through the semester. Would he have to leave? What would he do with his furniture? Could he come back?

He hopes the lawsuit will be successful, but he said his thinking has changed about the United States. “I find a lot of obstacles,” he said, and over time, those began to make him wonder. He loves the school and wants to complete his law degree. But he also wonders whether his future is in Europe.