TORONTO — Canada's Supreme Court ruled Thursday that a man born in Ontario to parents who were later revealed to be Russian spies may keep his Canadian citizenship.

The unanimous ruling in the case of Alexander Vavilov, who grew up in Canada and the United States as Alexander Foley, brought an end to a nearly decade-long legal battle.

Vavilov, 25, said the "relief" he felt at his "vindication" was "indescribable." But he spoke also of the "bitter realization of all the suffering I have had to endure to see my status as an ordinary Canadian restored."

"For the better part of a decade I was forced into exile from Canada," he said in a statement released by his lawyer. "I was forced onto the public stage unwillingly and deprived of my ability to pursue a normal life."

The victory for Vavilov, who had been barred from returning to the country of his birth, was a defeat for the government, which had said it was fighting for "the integrity of Canadian citizenship."

Vavilov and his brother Timofey, 29, were born in Toronto to what appeared to be an ordinary Canadian family. But they lost their citizenship after their parents pleaded guilty in a 2010 FBI sweep of Russian spies working under deep cover in the United States.

The brothers say they didn't know their parents were working for the Russian Foreign Intelligence Service.

The parents, Andrey Bezrukov and Elena Vavilova, arrived in Canada in the waning days of the Cold War, stole the identities of Donald Howard Heathfield and Tracey Lee Ann Foley — Canadians who had died as infants decades earlier — and began developing their “legends,” or background stories.

The family moved from Canada in 1995, when Alexander was an infant, and eventually settled in Cambridge, Mass., where “Donald” completed graduate studies at Harvard University. The brothers, who were born Alexander and Timothy Foley, never lived in Canada again but visited frequently, Alexander said in court filings.

It was in Massachusetts that Alexander’s parents were busted in 2010 as part of Operation Ghost Stories, the decade-long FBI investigation that yielded the arrests of 10 Russians operating under aliases in the United States.

The suspects were accused of carrying out deep-cover assignments for the Russian spy agency SVR, a successor to the KGB. The criminal complaints read like a John le Carré novel, with dead drops, stolen identities and messages written in invisible ink.

The 10 pleaded guilty to failing to register as agents of a foreign government and conspiracy to commit money laundering. They were ultimately swapped in Vienna for four Russians suspected of spying for the West.

Days before Bezrukov and Vavilova were deported, their sons were sent to Russia, where they changed their last names at the request of Canadian officials and were given Russian citizenship. During this process, Timothy also changed his first name.

The revelations left Alexander “feeling traumatized” and precipitated an “identity crisis,” his lawyer, Hadayt Nazami, wrote to the Canadian Supreme Court.

The real-life spy drama helped inspire the FX program “The Americans,” which tells the story of Russian spies and their U.S.-born children, who for much of the series are oblivious to their parents’ real identities.

The legal dispute dated to 2010, when Alexander made the first of several unsuccessful attempts to renew his Canadian passport.

Under Canadian law, babies born in the country obtain citizenship automatically, with one exception: those born to “a diplomatic or consular officer or other representative or employee in Canada of a foreign government.”

The case hinged in part on the definition of “employee.” A registrar of citizenship told Alexander in 2014 that he was never a Canadian national because his parents were employees of a foreign government. Alexander sought a judicial review, arguing that his parents were not formal employees of Russia.

A federal court agreed with the registrar and dismissed Alexander’s application for review. But an appeals court threw out that ruling in 2017 and reinstated his citizenship. The court found the exception applied solely to diplomatic officials with specific immunities and privileges, not to spies.

“The sins of parents ought not to be visited upon children without clear authorization by law,” Justice David Stratas wrote.

The Canadian government appealed the decision to the Supreme Court. That court ruled Thursday to dismiss the government’s appeal, leaving the appeals court decision to stand.

The court said it was not offering a “definitive interpretation” of the relevant clause.

“But we agree with the majority of the Court of Appeal that it was not reasonable for the Registrar to interpret [the clause] as applying to children of individuals who have not been granted diplomatic privileges and immunities at the time of the children’s birth,” the court said. “Given that V was born in Canada, his status is governed only by the general rule of citizenship by birth. He is a Canadian citizen.”

Alexander called the ruling “recognition that not only do I feel Canadian, but I am Canadian in the eyes of the law.”

"No longer will I have to live in purgatory," he said. "I can finally unquestionably exercise my rights and responsibilities as a Canadian citizen … Having my citizenship finally respected brings me great joy."

Nazami said Alexander would now return to Canada.

Timofey Vavilov was also seeking Canadian citizenship, but Alexander’s case was further along in the process. Rémi Larivière, a spokesman for Canada’s immigration and citizenship department, said the government will comply with the Supreme Court decision, and both Alexander and Timofey are Canadian citizens.

The citizenship registrar had alleged that Canada’s spy agency told the federal government that Timofey was “sworn in” by the Russian Foreign Intelligence Service before his parents were arrested. Timofey said in an affidavit that the allegations were false.

Nazami wrote that the brothers have felt little attachment to Russia since they arrived in 2010.

“[Alexander] and his brother have tried to remain outside of Russia as much as possible since then,” the lawyer wrote in his submission to the Supreme Court. Alexander, he said, was “studying in other countries while being barred from coming to Canada, the only country he feels he belongs.”