Harvard, pictured here, joined MIT in suing the Trump administration over a rule barring international students from coming to the United States to attend colleges offering only online classes. (Adam Glanzman/Bloomberg News)

Harvard University and the Massachusetts Institute of Technology sued the Trump administration Wednesday over an order that would require international 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 international students. It also marks a new battle line in the war between President 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 S. Bacow, told the Harvard community Wednesday.

On Wednesday, Northeastern University in Massachusetts joined the suit, with Joseph E. Aoun, the school’s president, saying the new guidance “creates chaos for international students and has the effect of weakening American higher education — one of our nation’s signature strengths.”

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 yet, but the guidance issued Monday stunned university officials and panicked students. Though international students were previously required to take classes in person, the government had offered schools and students flexibility this spring, after the pandemic shut down most campuses. And it had said that 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 international students would be allowed in the country even if they weren’t 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 international students, and MIT 4,000. In their lawsuit, the universities argue that U.S. Immigration and Customs Enforcement’s decision was designed to force universities to conduct in-person classes, part of an apparent 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 the U.S. District Court in Massachusetts, seeks a temporary restraining order that would quickly stop the government from enforcing the policy. The schools argue that 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 continued efforts to limit and reduce the presence of international students in the country, the lawsuit argues.

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

“Anything short of 100 percent online classes,” he told CNN in an interview. Cuccinelli denied 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 told CNN.

The ICE ruling frightened international students, who worried 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 broke 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 are mobilizing to defend international students. Some are brainstorming ways to work around the administration’s policy, creating makeshift classes for international students.

Dana R. Fisher, a sociology professor at the University of Maryland at College Park, said she woke up Wednesday to 25 emails from terrified students. She had fielded even more frantic emails 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 they don’t 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, L. Rafael Reif, told campus 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 international 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 M. Crow, president of Arizona State University, which has more than 10,000 international 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 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 if his future is in Europe.

Lauren Lumpkin contributed to this report.