OTTAWA (Reuters) - Kevin Garratt, a Canadian held in China for two years and charged with spying, returned to Canada on Thursday in what was a diplomatic triumph for Prime Minister Justin Trudeau.

Kevin Garratt, a Canadian held in China for two years on suspicion of spying, hugs his wife Julia Garratt after being deported by Chinese authorities, in Vancouver, British Columbia, Canada, in this handout picture taken and released by the Garratt family September 15, 2016. Courtesy of the Garratt Family/Handout via Reuters

The Canadian leader had raised Garratt’s case during an official visit to China this month when he both pressed for closer economic ties and openly discussed human rights, which is a sensitive matter in Beijing.

“On Thursday, September 15th, Kevin was deported from China and has returned to Canada to be with his family and friends,” the family said in a statement requesting privacy.

A Canadian government official said Garratt had been formally sentenced earlier in the week and then released on bail. He flew into the Pacific city of Vancouver.

In a statement, Trudeau said he was delighted that Garratt had returned safely.

Garratt and his wife, Julia, were detained in August 2014 near China’s border with North Korea. He was charged with spying and stealing state secrets.

Julia, who was not charged, was released on bail and left the country.

A source close to the case, who requested anonymity because of its sensitivity, said Garratt was tried on April 20.

The release came as a surprise, since there were few signs of a breakthrough when Trudeau flew to China. Indeed, while he was in Beijing, the Garratt family expressed their frustration at the lack of progress.

“We raised this case at the highest levels when we were there. It’s just indicative of the mature and healthy relationship we have that we can do so,” said the government official, who spoke on the condition of anonymity.

‘RULED BY LAW’

James Zimmerman, the Beijing-based lawyer for Garratt, said: “The family appreciates the strong, persistent efforts of the Canadian government to secure Kevin’s release.”

The affair had undermined efforts by both countries to boost economic ties. China wants a free trade deal with Canada but opinion polls show most Canadians are cool to the idea, in part because of Beijing’s human rights record.

The Canadian official declined to say what the Chinese might have received in return for Garratt’s release.

Chinese Premier Li Keqiang is due to visit Canada from Sept. 21-24.

A court in the city of Dandong, near the North Korean border, ruled on Garratt’s case on Tuesday, China’s Foreign Ministry said in a statement emailed to Reuters.

“China is a country ruled by law,” the ministry said in the statement.

“China’s judiciary handled the case seriously and in accordance with the law, thoroughly ensuring Kevin Garratt’s litigation rights and thoroughly respecting and implementing Canada’s consular rights.”

Brock University professor Charles Burton, a former Canadian diplomat who had served two postings in China, said in an email that Beijing was likely to press for the return of what it has said are corrupt officials who had fled to Canada to avoid arrest.

China does not have extradition treaties with United States, Canada or Australia, which Chinese state media say are the three most popular destinations for suspected economic criminals.