New York CNN Business  — 

Huawei CFO Meng Wanzhou and the US Department of Justice on Friday entered an agreement to defer prosecution of US charges against her until late 2022, after which point the charges could be dropped.

The deal, which allowed Meng to return to China, could bring to an end a nearly three-year legal saga that has complicated relations between the United States, China and Canada.

Meng left Canada Friday on a flight for China chartered by the Chinese government, state-run news agency Xinhua reported.

In a lengthy post on her WeChat account Saturday, Meng described tearing up as her flight from Vancouver to Shenzhen crossed the North Pole and praised China’s ruling Communist Party. A CNN source has seen the post which is not open to be publicly viewed.

“As we get closer to home, I feel increasingly emotional, with tears welling up in my eyes. Under the leadership of the Chinese Communist Party, our motherland is moving toward prosperity. Without this strong motherland, I wouldn’t have my freedom today,” she wrote. “I thank my beloved motherland, and I thank the Party and the government … for shining a light during my darkest hours and guiding me in my long journey home.”

Following her release, two Canadians detained by China for nearly three years were also freed, Canadian Prime Minister Justin Trudeau said Friday.

The US case centered on whether Meng, who is also the daughter of Huawei founder Ren Zhengfei, misled HSBC about Huawei’s relationship with an Iranian subsidiary, Skycom, which the US alleges could have put the bank at risk of sanctions violations.

Meng appeared virtually in a court in Brooklyn, New York, and pleaded not guilty to charges of conspiracy to commit bank fraud, bank fraud, conspiracy to commit wire fraud, and wire fraud.

However, as part of the deal, Meng confirmed that the statement of facts in the deferred prosecution agreement are true. Those facts include that she misrepresented Huawei’s relationship with Skycom to HSBC, according to court documents. If she says or implies otherwise, it could violate the terms of the deal and result in her prosecution.

“In entering into the deferred prosecution agreement, Meng has taken responsibility for her principal role in perpetrating a scheme to defraud a global financial institution,” Acting US Attorney Boeckmann said in a statement Friday.

The statement of facts Meng admits to could contribute to the United States’ ongoing case against Huawei. (Huawei declined to comment for this story.)

Assistant US Attorney David Kessler told the court that the parties had entered into a deferred prosecution agreement until December 1, 2022. If Meng complies with the provisions of the agreement, the US government will dismiss the charges against her on that date.

District Judge Ann Donnelly accepted the deferred prosecution agreement during the Friday hearing.

Huawei and Meng’s team previously denied the US allegations, saying that HSBC executives knew of Huawei’s relationships with Skycom. They have also claimed that the US case — which was filed amid former President Donald Trump’s trade war with China — was politically motivated.

Meng was arrested in December 2018 at the Vancouver airport at the behest of the US government. She has been living under house arrest in her multimillion-dollar homes in the city as proceedings to extradite her to stand trial in the United States work their way through Canadian courts. Meng’s team has also opposed extradition; their arguments include claims that Meng’s rights were violated during her arrest at the airport.

The plea agreement allows for her release on a personal recognizance bond, and the DOJ plans to withdraw its request for Meng’s extradition from Canada, Kessler said.

The extradition proceedings have been nearing their end. Last month, hearings in the case concluded and Canadian Associate Chief Justice Heather Holmes said she would announce the date for her ruling on whether Meng should be extradited in a court appearance on October 21.

The Justice Department reportedly offered a resolution last year to the standoff that ensnared Canada over the US charges against her.

Speaking at a news conference on Friday, Canadian Prime Minister Trudeau said Michael Kovrig and Michael Spavor boarded a plane headed for Canada at about 7:30 p.m. ET Friday night and would land in Canada sometime Saturday.

Former diplomat Kovrig and businessman Spavor had been held in China since late 2018. They were arrested on espionage charges in China shortly after Meng’s arrest in Canada. However, China has consistently denied that the cases were in any way connected.

Correction: An earlier version of this story stated that Meng Wanzhou was expected to plead guilty to US charges. She pleaded not guilty, but as part of the deferred prosecution agreement she admitted to a series of facts, including that she misrepresented Huawei's relationship with Skycom to HSBC.

Additional reporting from CNN’s Steven Jiang and Beijing bureau.