WASHINGTON (Reuters) - The U.S. Supreme Court ruled on Monday that children waiting with their parents for immigration visas must go to the back of the line once they reach the age of 21.

The exterior of the U.S. Supreme Court is seen in Washington March 5, 2014. REUTERS/Gary Cameron

The court was divided 5-4 in deciding that only in limited circumstances does federal immigration law allow for children to retain their place in line after they become adults.

The case concerns a program that allows people who are U.S. citizens or legal residents to sponsor relatives who live overseas. People often have to wait for years for approval of their visa applications and the number of visas available is capped each year.

The litigation is unconnected to recent reports of unaccompanied children crossing the U.S. border illegally.

The court endorsed the federal government’s interpretation of the law, which was that only children of permanent U.S. residents were eligible to keep their place in line once they reached the age of 21.

The case was brought by two groups of plaintiffs, including Rosalina Cuellar de Osorio, who was told in November 2005 that her family was at the front of the line to obtain visas to enter the United States from El Salvador. The family was told at the time that her son, Melvin, who had turned 21 just months earlier, would no longer be eligible.

The Supreme Court decided to hear the issue after the San Francisco-based 9th U.S. Circuit Court of Appeals ruled in September 2012 that a broader category of visa applicants was eligible than had been argued by the administration of President Barack Obama.

The five justices in the majority were split over which legal rationale to adopt. Justice Elena Kagan, who wrote the majority opinion, was joined in full by only Justices Anthony Kennedy and Ruth Bader Ginsburg.

Kagan wrote that when a statute is unclear, the court was required to defer to the interpretation offered by the government. Chief Justice John Roberts and Justice Antonin Scalia agreed with the judgment but offered a different rationale.

Justice Sonia Sotomayor, who, like Kagan, was appointed by Obama, wrote in a dissenting opinion that the law was clearer than the majority suggested and that the case should have been decided with a “commonsense approach.”

The case is Scialabba v. de Osorio, U.S. Supreme Court, No. 12-930.