A federal judge in California ruled Thursday that a twin son of a gay married couple has been an American citizen since birth, handing a defeat to the U.S. government, which had only granted the status to his brother.

The State Department was wrong to deny citizenship to 2-year-old Ethan Dvash-Banks because U.S. law does not require a child to show a biological relationship with their parents if their parents were married at the time of their birth, District Judge John F. Walter found.

A lawsuit filed by the boys' parents, Andrew and Elad Dvash-Banks, sought the same rights for Ethan that his brother, Aiden, has as a citizen.

Each boy was conceived with donor eggs and the sperm from a different father — one an American, the other an Israeli citizen — but born by the same surrogate mother minutes apart.

The government had only granted citizenship to Aiden, who DNA tests showed was the biological son of Andrew, a U.S. citizen. Ethan was conceived from the sperm of Elad Dvash-Banks, an Israeli citizen.

The suit was one of two filed last year by an LGBTQ immigrant rights group that said the State Department is discriminating against same-sex binational couples by denying their children citizenship at birth. The cases filed in Los Angeles and Washington by Immigration Equality said the children of a U.S. citizen who marries abroad are entitled to U.S. citizenship at birth no matter where they are born, even if the other parent is a foreigner. Only the Los Angeles case was decided Thursday.

The State Department did not immediately respond to an email seeking comment on the ruling. Previously the department pointed to guidance on its website that said there must be a biological connection to a U.S. citizen to become a citizen at birth.

"This family was shocked and appalled and angry when they were told their family wasn't legal," said Aaron Morris, executive director of Immigration Equality. "They wanted their twin boys to be treated exactly the same."

Morris said the government wrongly applied a policy for children born out of wedlock to married same-sex couples.

Walter agreed, writing that the State Department statute does not contain language "requiring a 'blood relationship between the person and the father' in order for citizenship to be acquired at birth."

"This is justice! We are hopeful that no other family will ever have to go through this again. It's like a giant rock has been removed from our hearts," Andrew and Elad Dvash-Banks said in a statement provided by Immigration Equality.

Andrew Dvash-Banks was studying in Israel when he met his future husband, Elad, an Israeli citizen. Because they couldn't marry at the time in the U.S. or in Israel, they moved to Canada, where they wed in 2010. The children were born by a surrogate in September 2016.

Everything seemed fine until the couple brought their cranky infants to the American consulate in Toronto a few months later to apply for citizenship and the woman at the counter began asking probing questions they found shocking and humiliating.

The consular official told them she had discretion to require a DNA test to show who the biological father was of each boy and without those tests neither son would get citizenship. The men knew that Andrew was Aiden's biological father and Elad was Ethan's but they had kept it a secret and hadn't planned on telling anyone.

After submitting the DNA test results that proved who fathered each boy, the couple received a large and small envelope from the U.S. on March 2. The big one included Aiden's passport. The other was a letter notifying Andrew that Ethan's application had been denied.

The family has since moved to Los Angeles to be closer to Andrew Dvash-Banks' family.

The other case involves two women, one from the U.S., and one from Italy, who met in New York, wed in London and each gave birth to a son. The State Department didn't recognize the couple's marriage, the lawsuit said, and only granted citizenship to the boy whose biological mother was born and raised in the U.S.