Mr. Obama’s other appointee, Justice Sonia Sotomayor, dissented. She was joined by Justices Stephen G. Breyer and Clarence Thomas. Justice Samuel A. Alito Jr. filed a separate dissent.

The case involved Rosalina Cuellar de Osorio, who immigrated from El Salvador in 1998 with her 13-year-old son. After years of waiting, her son turned 21. The administrative tribunal ruled that when he turned 21, he lost his place in the line for permanent residence and would have to start over. The family challenged the tribunal’s decision in Federal District Court and lost. When the case was heard by the full United States Court of Appeals for the Ninth Circuit, in San Francisco, it reversed the decision, saying the 2002 law provided that children listed on their parents’ green card applications would automatically be converted to another category when they turned 21. The Obama administration appealed.

In her 33-page opinion, Justice Kagan balanced her analysis of the complexities of immigration law with seemingly humorous asides. “Those hardy readers who have made it this far will surely agree with the ‘complexity’ point,” she declared in a parenthetical phrase that spilled over from Page 13 to Page 14. That was a few pages after she quoted the full text of the law in a footnote that she said was “for the masochists among this opinion’s readers.”

Justice Kagan dismissed the immigrants’ arguments in the case as “resourceful (if Rube Goldbergish)” but hobbled by what she called “statutory inconsistency.”

“We still see no way to apply the concept of automatic conversion to the respondents’ children and others like them,” she said, adding that courts had to defer “to the board’s expert judgment about which interpretation fits best with, and makes most sense of, the statutory scheme.”

Alina Das, a co-director of the Immigrant Rights Clinic at New York University, said aged-out children of immigrants would “continue to be in limbo, waiting for leadership from the administration and Congress to make sure that they’re back on a path to citizenship.”