The Supreme Court ruled Monday that the vast majority of immigrant children who turn 21 while awaiting approval of their families’ visa applications must restart a process that takes years.

The divided court deferred to the Obama administration’s reading of a law passed in 2002 that attempted to bring order to the immigration process, in which there are far more applications than spots available.

The law is so ambiguous — one section “is through and through perplexing,” wrote Justice Elena Kagan — that it is best to leave interpretation to the Board of Immigration Appeals, she said. The federal agency has said that certain classes of applicants lose their favored status as children when they turn 21 — even if the process started years earlier.

Kagan said the decision would primarily affect nieces, nephews and grandchildren of U.S. citizens and legal permanent residents who are trying to reunite their families. The decision does not touch on the recent migration of thousands of children traveling on their own across the Mexican border.

The case required a deep dive into complex immigration law and divided the court in several ways. Kagan’s opinion was joined by Justices Anthony M. Kennedy and Ruth Bader Ginsburg. Chief Justice John G. Roberts Jr. and Justice Antonin Scalia agreed with the agency’s interpretation of the law but did not go along with Kagan’s description of the law as having “conflicting” directives.

Justice Sonia Sotomayor, who like Kagan was nominated to the court by President Obama, led the dissent. She said the law clearly was intended to keep families together and that children who “aged out” during the process should not have to start the process to get their own visas.

She was joined by Justices Clarence Thomas and Stephen G. Breyer. Justice Samuel A. Alito Jr. filed his own dissent.

The agency’s interpretation of the law was challenged by Rosalina Cuellar de Osorio, a Salvadoran immigrant who was the principal beneficiary of a petition filed by her mother, a U.S. citizen. Her 13-year-old son Melvin was what was called a derivative beneficiary.

The application was approved in 1998, but only a certain number of visas are available each year, and Cuellar de Osorio’s did not come until 2005 — four months after Melvin turned 21. The parents immigrated, but government officials said Melvin no longer qualified as an eligible child, and he was placed at the back of the line, resulting in a wait of several more years.

The U.S. Court of Appeals for the 9th Circuit ruled for the family, but other courts have deferred to the agency, setting up Monday’s decision.

Kagan said it was the court’s precedent to defer to agencies when the law is ambiguous and said the government had reasons for its rules. In the “unavoidably zero-sum world of allocating a limited number of visas,” Kagan wrote, admitting some means that others will be left out.

Sotomayor said it was clear that the law’s intent was to treat all those who become 21 during the wait for visas the same and that the court was wrong to “construe the statute as a self-contradiction that was broken from the moment Congress wrote it.”

A group of lawmakers including Sens. John McCain (R-Ariz.) and Dianne Feinstein (D-Calif.), submitted a brief rejecting the administration’s view of the law. But any legislative remedy to the decision would likely be complicated by Congress’s impasse over comprehensive immigration reform.

The case is Scialabba v. Cuellar de Osorio.

Pollution deadlines

The court by a 7 to 2 vote said that a group of North Carolina landowners had missed a state deadline for suing a company that contaminated their drinking water decades ago and ruled that a federal law did not protect such suits.

The decision affects a handful of other states that have such time limits and is a blow for a suit on the other side of North Carolina where families of several thousand former Marines are suing over contaminated drinking water at Camp Lejeune.

The ruling resolved a tension between federal environmental laws and state restrictions. Federal law says that statutes of limitation do not begin to run until a plaintiff discovers, or reasonably should have discovered, the harm caused by a pollutant.

“A person who is exposed to a toxic contaminant may not develop or show signs of resulting injury for many years, and so Congress enacted [the law] out of concern for long latency periods,” Kennedy wrote.

But while the federal law on that point is clear, Kennedy said, it is silent about another deadline. A handful of states, North Carolina among them, require that any legal action be brought within a certain number of years after the last polluting act. In North Carolina, that is 10 years.

The case involved land where a company called CTS Corp. ran an electronics plant until 1985. It later sold the land. Property owners discovered the pollution in 2009 and filed a suit within the two years required under federal law.

But Kennedy and the majority said the North Carolina law barred the suit. Congress was aware of such state “statues of repose,” he said, but decided not to act to preempt them.

Ginsburg and Breyer dissented. The federal law displaced the state’s deadline, Ginsburg wrote, and was in keeping with Congress’s intent that plaintiffs get their day in court.

“The court allows those responsible for environmental contamination, if they are located in the still small number of states with repose periods, to escape liability for the devastating harm they cause, harm hidden from detection for more than 10 years,” she wrote.

The case is CTS Corp. v. Waldburger.