Two Canadians who were detained in China on spying charges were released from prison on Friday, Prime Minister Justin Trudeau said. Subsequently, the detainees were flown out of the country. This release comes after a top executive of Chinese communications giant Huawei Technologies inked a deal with the US Justice Department over fraud charges.

With this, the three-way geopolitical wrangling was brought to an abrupt end after three years of dispute that disturbed the relation among Washington, Beijing and Ottawa. The three-way deal enabled China and Canada to each bring home their own detained citizens while the US wrapped up a criminal case against a prominent tech executive that for months had been mired in an extradition fight.

After the deal was made, Huawei’s chief finance officer, Meng Wanzhou, reached an agreement with federal prosecutors that called for fraud charges against her to be dismissed next year and allowed for her to return to China immediately.

As part of the deal, the daughter of the company’s founder accepted responsibility for misrepresenting the company’s business dealings in Iran.

An hour after her planes left Canada for China, the Canadian PM announced that Canadians Michael Kovrig and Michael Spavor were also on their way home.

The men were arrested in China in December 2018, shortly after Canada arrested Meng on a US extradition request. Many countries labeled China’s action “hostage politics.”

“These two men have been through an unbelievably difficult ordeal. For the past 1,000 days, they have shown strength, perseverance and grace and we are all inspired by that,” Trudeau said.

The deal was reached as President Joe Biden and Chinese counterpart Xi Jinping have sought to tamp down signs of public tension.

“The U.S. Government stands with the international community in welcoming the decision by People’s Republic of China authorities to release Canadian citizens Michael Spavor and Michael Kovrig after more than two-and-a-half years of arbitrary detention. We are pleased that they are returning home to Canada,” U.S. Secretary of State Antony Blinken said in a statement.

In his UNGA address, Biden maintained that he had no intention of starting a “new Cold War,” while Xi told world leaders that disputes among countries “need to be handled through dialogue and cooperation.”

(With inputs from Associated Press)