BOSTON — A federal judge on Friday dismissed a lawsuit challenging a requirement that students at the University of Massachusetts campuses in Boston and Lowell be fully vaccinated against the coronavirus in order to return to campus.

Students at the schools sued in July, asking the judge to find the vaccination mandates to be unconstitutional. The UMass Boston student also alleged she was improperly denied a religious exemption.

U.S. District Judge Denise Casper said the schools have a strong interest in reducing the spread of the disease. And she found that despite the students’ assertion that the policy is “arbitrary or not based in science,” the schools “based the decision upon both medical and scientific evidence and research and guidance and thus is at least rationally related to these legitimate interests.”

The judge also noted that students who refuse to get vaccinated may still take online classes or defer their enrollment a semester. But even if the policy meant they would be deprived of a UMass education, their argument still fails, she said.

“Moreover, the balance of equities tips in Defendants’ favor given the strong public interest here that they are promoting—preventing further spread of COVID-19 on campus, a virus which has infected and taken the lives of thousands of Massachusetts residents,” she wrote.

UMass President Marty Meehan applauded the ruling for allowing the school to “continue taking the steps necessary to protect the health and safety of our students, staff, and faculty.”

“It also sends a strong message to those higher education institutions across the country that are putting the well-being of their campus communities first as we all begin a new academic year,” he said in an emailed statement.

An email seeking comment was sent to an attorney representing the students.