Open this photo in gallery Canada's ambassador to the United States, David MacNaughton, played a central role in the renegotiation of the trade deal that is now known as the USMCA. J. Scott Applewhite/The Associated Press

David MacNaughton, who played a critical role in the renegotiation of the North American free-trade agreement, is leaving as Canada’s ambassador to the United States to join a Silicon Valley technology company.

Mr. MacNaughton said Thursday that it was time to return home after 3½ years serving as envoy at the country’s most important diplomatic mission during a time when continental free trade was under threat from U.S. President Donald Trump.

“The President had campaigned against [NAFTA] and said he was going to rip it up," Mr. MacNaughton said during a news conference at the Canadian embassy in Washington. "Our dependence on the U.S. for our prosperity was certainly being challenged. Because we stuck together … we are able to achieve what I think … is a pretty damn good agreement.”

Story continues below advertisement

Mr. MacNaughton is heading to Palantir Technologies Inc., a data-analytics company based in Palo Alto, Calif., as the Toronto-based president of its Canadian unit. Palantir builds data-mining software for clients such as banks, manufacturers, pharmaceutical companies and government agencies, including law-enforcement and intelligence services. The company was founded in 2003, in part with funding from the Central Intelligence Agency; its surveillance technology has been used in counterterrorism work, and Palantir reportedly played a role in the campaign to track down Osama bin Laden.

“I’m fascinated by the opportunity to use data and technology to help people make better decisions,” Mr. MacNaughton said in an interview with The Globe and Mail. He said his role at Palantir will focus on building relationships in sectors such as health care, energy and financial services. Palantir opened offices in Toronto and Ottawa five years ago and has approximately 30 employees in Canada and 2,000 staff in total.

His departure comes as Canada and Mexico attempt to get the new free-trade pact approved by the U.S. Congress, where the Democrats are seeking changes to labour protection and prescription drugs in the deal, known as the United States-Mexico-Canada Agreement (USMCA).

Mr. MacNaughton has spent recent months trying to persuade the Democratic-led U.S. House of Representatives to ratify USMCA, an outcome that remains in doubt. The deal also still needs Canadian government approval. Mexico ratified the agreement in June.

Mr. MacNaughton said he remains confident that the new agreement will pass Congress, although it is possible there may be side agreements or tweaking of some of the language within the trade pact.

“I do think there is broad agreement even among the Democrats,” he said. “I think when it comes down to a vote, it will pass both Houses.”

A key political adviser to Prime Minister Justin Trudeau, Mr. MacNaughton officially leaves his U.S. post on Sept. 1. “I had long planned to complete my work ahead of the fall election,” Mr. MacNaughton said, “particularly following the lifting of steel and aluminum tariffs – something I was absolutely determined we would get done before I left this job − and Congress’s rising for the summer."

Story continues below advertisement

Shyam Sankar, president of Palantir, said recruiting Mr. MacNaughton is part of a strategy to do more business at Canadian companies with international ambitions. “David’s role, and ours, is to help Canada Inc. win on a global stage," Mr. Sankar said.

Palantir is named after the fictional seeing stones used to communicate and view distant events in J.R.R. Tolkien’s The Lord of the Rings and is currently a private company. It is widely expected to go public in the next two years in a transaction that is likely to value the company at more than US$40-billion. Mr. Shankar declined to comment on the company’s financial plans.

Palantir’s software helps banks such as JPMorgan Chase & Co. scrub data from multiple sources to spot fraud, while pharmaceutical companies use its products to sift through the results of drug trials or track disease outbreaks. The company’s biggest customers are governments – Palantir is one of the biggest suppliers to U.S. government agencies. As a former senior civil servant, Mr. MacNaughton faces restrictions on pitching the federal government on behalf of Palantir that will expire in up to seven years.

The Prime Minister named career public servant Kirsten Hillman, currently Canada’s deputy ambassador to the United States, as acting ambassador. The appointment of a new ambassador in Washington will come after the Oct. 21 federal election.

Mr. Trudeau had tapped Mr. MacNaughton because of his extensive experience working in the United States and profound understanding on how Washington operates. For many years, Mr. MacNaughton worked in New York as chair of Hill & Knowlton, one of the world’s most influential consulting companies. He spent much of his time in Washington lobbying political figures and senior government officials.

As Washington envoy, he dealt with frequent broadsides from Mr. Trump and various White House officials against Mr. Trudeau, Foreign Affairs Minister Chrystia Freeland and others during the hectic trade talks, which resulted in a deal last September.

Story continues below advertisement

The Prime Minister credited Mr. MacNaughton for helping to shape the Canadian strategy for the talks that included outreach efforts to U.S. congressional representatives and governors and making the point that Canada is the largest foreign market for U.S.-made goods and services.

"David’s skill in bridging partisan and ideological divides – always putting Canadians’ interests first, never deviating from objectives he knew to be both possible and desirable – has been unparalleled,” Mr. Trudeau said in a statement.

He also praised the envoy for the "critical role in persuading U.S. lawmakers and the administration to end U.S. tariffs on Canadian steel and aluminum, allowing Canada to correspondingly remove our reciprocal tariffs last May.”

Kelly Craft, the former U.S. ambassador to Canada who was recently confirmed by the U.S. Senate as her country’s chief diplomat to the United Nations, described Mr. MacNaughton as a “fierce negotiator” but also said he was a “cherished friend.”

Former prime minister Brian Mulroney, who was a key adviser to the Trudeau government during the trade talks, said Mr. MacNaughton excelled in dealing with the often chaotic Trump administration.

Mr. MacNaughton also won high praise from the Business Council of Canada, which represents the country’s largest corporations, for his skill in dealing with the White House.

Story continues below advertisement

Mr. MacNaughton, who co-chaired the Liberals’ 2015 election campaign in Ontario, will not have a formal role in the coming federal election but said he is ready to offer advice once the writ is dropped in September.

“I am available to the Prime Minister and to my friends and colleagues to provide advice and counsel whenever they want to seek it,” he said.

Your time is valuable. Have the Top Business Headlines newsletter conveniently delivered to your inbox in the morning or evening. Sign up today.