The Supreme Court has dealt a blow to U.S. immigration officials in a closely watched case by ruling that a broad state anti-drug law may not be enough to justify deportation.

By a 7-2 vote, the court ruled that a Tunisian man convicted of carrying pills in his sock should not have been removed from the U.S. for that reason.

The case involves Moones Mellouli, who arrived in the country on a student visa and earned bachelor's and master's degrees from American schools. He went on to teach math at the University of Missouri. But after police arrested him in Kansas for driving under the influence five years ago, they found four orange tablets hidden in his sock.

Mellouli eventually pleaded guilty to a single misdemeanor charge for possessing drug paraphernalia, with the sock being the paraphernalia. U.S. authorities determined that was enough to deport him.

Government lawyer Rachel Kovner acknowledged the unusual facts in the case at oral argument this year.

"Strange feature of this case is that it involves an item that's not usually thought of as drug paraphernalia," Kovner said. "The classic paraphernalia items ... are things like hypodermic needles and scales and substances used to mix with drugs before sale."

But Jon Laramore, a lawyer for Mellouli, argued the government was stretching the law.

"Possession of paraphernalia is not a federal offense," Laramore told the justices. "One cannot be prosecuted federally for possessing drug paraphernalia."

And in order to deport someone, Laramore said, the U.S. needs to show the drug at issue is on the federal Controlled Substances list.

"The government wants any drug conviction to be a deportable offense even if it's clearly for a non-federal drug," and that can't be right, he argued.

The Supreme Court ruled that Mellouli's conviction should not trigger deportation.

Justice Ruth Bader Ginsburg, who wrote for the court majority, said his crime should not be considered enough to remove someone from the country under federal law.

And about those pills hidden in Mellouli's sock? They turned out to be Adderall, a drug that's popular on campuses to help students stay awake.

That point was not lost on Justice Elena Kagan, a former law school dean, during oral argument.

"He had four pills of Adderall, which if you go to half the colleges in America people, you know, and just randomly pick somebody, there would be a decent chance," Kagan said to laughter in the courtroom.

In dissent, Justice Clarence Thomas wrote he sees "nothing absurd about removing individuals who are unwilling to respect the drug laws" where they live.

Copyright 2016 NPR. To see more, visit http://www.npr.org/.