Updated

The U.S. Supreme Court sided Tuesday with a Mexican immigrant who faced deportation after he was convicted of having consensual sex with his girlfriend who was 16 at the time.

The justices ruled unanimously that while Juan Esquivel-Quintana committed a crime under California law, his conduct did not violate federal immigration law.

It's a crime in California to have sex with anyone under 18 if the age difference is more than three years. That applied to Esquivel-Quintana, who had sex with his 16-year-old girlfriend before and after his 21st birthday.

But Esquivel-Quintana argued that his conduct would have been legal under federal law and the laws of 43 other states that are less strict.  The government countered – and said the courts should defer to immigration officials in interpreting laws that are vague.

The case is the first one before the Supreme Court that names Attorney General Jess Sessions as a party – though the incident in question took place before Sessions was confirmed to his new post.

The Associated Press contributed to this report.