Ottawa (CNN) President Barack Obama sought to reassure his counterparts in Canada and Mexico Wednesday that a potential Donald Trump presidency wouldn't throw cross-border ties into turmoil, even as he pushed back on the GOP candidate's platform.

Expressing confidence that immigration wouldn't be shut off and trade deals would persist, Obama argued against the type of protectionist policies that Trump has espoused on the campaign trail. And he cast the presumptive GOP nominee as a failed historical archetype.

"We've had times throughout our history where anti-immigration sentiment is exploited by demagogues," Obama said. "The language is identical. But guess what? They kept coming, and they kept coming because America offered possibility for their children and grandchildren."

Convening a final North American leaders' summit even as the U.S. presidential contest throws crucial cross-border issues into dispute, Obama and his counterparts discussed trade, security and climate change during a day of talks in the Canadian capital.

But during an afternoon press conference, Trump was the topic du jour. Reporters quizzed Obama, Mexican President Enrique Pena Nieto and Canadian Prime Minister Justin Trudeau extensively about the candidate's vow to construct a border wall and withdraw from free trade deals.

Obama's visit comes just a day after Trump lambasted the agreements that have linked the U.S. and its northern and southern neighbors in tight trade ties, vowing to withdraw from the much-maligned NAFTA agreement while insisting he'd also scuttle Obama's proposed replacement, the Trans-Pacific Partnership. Expected Democratic challenger Hillary Clinton also now opposes TPP.

"The prescription of withdrawing from trade deals and focusing solely on your local market, that's the wrong medicine," Obama said Wednesday, acknowledging fears of globalization were well founded.

"What we have seen are trend lines of growing inequality and stagnant wages and a smaller share of growth going to workers and a larger portion going to the top," Obama said. "That's a real problem."

Like all of his meetings with foreign leaders in the past year, Obama was ready to face questions about Trump, who kicked off his campaign one year ago accusing Mexicans of being rapists and criminals.

Pena Nieto has sharply criticized the presumptive GOP nominee, even comparing his style of politics to dictators like Hitler and Mussolini. He's dismissed outright the suggestion that Mexico would fund Trump's proposed border wall, as the presumptive nominee has called for.

On Wednesday, Pena Nieto reiterated his opposition, though he said he was prepared to work with whomever is election U.S. president.

"Political actors, by using populism and demagoguery, they choose the easier way to solve the challenges of today's world," he said through a translator. "Things are not that simplistic."

Trudeau has been more circumspect, saying he's ready to work with whoever is elected in the United States.

"I look forward to working with whomever the American people elect as their president in November," he said.

After an hour of talks with Pena Nieto earlier in the day, Obama used a photo spray to push back on Trump's anti-immigrant language, heralding the contributions of Mexican-Americans.

"The United States is not just a friend and neighbor of Mexico but the very character of the United States is shaped by Mexican Americans who have shared our culture, our politics, our business," he said. "All too often we're hearing rhetoric that ignores the enormous contributions that have been made by Mexican Americans and the enormous strengths we draw from the relationship."

Mexican President Enrique Pena Nieto, Canadian Prime Minister Justin Trudeau and US President Barack Obama arrive for the North American Leaders Summit and Leaders Summit at the National Gallery of Canada on June 29, 2016 in Ottawa, Ontario.

Meanwhile, Obama and fellow world leaders continue to size up the ramifications of last week's vote in the United Kingdom to exit to European Union, a topic that's certain to come up in the conversations in Canada.

And the President is still assessing Tuesday's terror attack at Istanbul's international airport, yet another incident of global terror that has intruded into planned conversations with world leaders. Recent trips to Asia, South America and Europe have been similarly overshadowed. Obama remarked on the attack Wednesday, saying the U.S. was "heartbroken" at the violence.

Photos: Canada's Justin Trudeau visits U.S. President Barack Obama toasts Canadian Prime Minister Justin Trudeau during a state dinner at the White House on Thursday, March 10. Hide Caption 1 of 10 Photos: Canada's Justin Trudeau visits U.S. Singer-songwriter Sara Bareilles, left, performs during the state dinner at the White House on March 10. Hide Caption 2 of 10 Photos: Canada's Justin Trudeau visits U.S. President Obama and first lady Michelle Obama greet Prime Minister Trudeau and his wife, Sophie Gregoire Trudeau, at the North Portico of the White House for the state dinner on March 10. Hide Caption 3 of 10 Photos: Canada's Justin Trudeau visits U.S. Trudeau listens as Obama speaks during a bilateral news conference in the Rose Garden of the White House on March 10. "No two nations agree on everything," Obama said. "Our countries are no different, but in terms of our interests and values and how we approach the world, few countries match up the way the United States and Canada do." Hide Caption 4 of 10 Photos: Canada's Justin Trudeau visits U.S. Michelle Obama and Sophie Gregoire-Trudeau sing with schoolchildren during a program at the U.S. Institute of Peace in Washington. Hide Caption 5 of 10 Photos: Canada's Justin Trudeau visits U.S. President Obama welcomes Prime Minister Trudeau to the Oval Office on March 10. Though Trudeau's predecessors made regular trips to Washington, this is the first official visit by a Canadian premier in 19 years. Hide Caption 6 of 10 Photos: Canada's Justin Trudeau visits U.S. The couples wave from the White House balcony on March 10. Hide Caption 7 of 10 Photos: Canada's Justin Trudeau visits U.S. The two leaders listen to the Canadian national anthem during a ceremony on the South Lawn of the White House on March 10. Obama and Trudeau are clearly friendly in each other's company, making small talk amid the grandeur of the official state welcome. Hide Caption 8 of 10 Photos: Canada's Justin Trudeau visits U.S. A fife and drum corps performs during the arrival ceremony on the South Lawn. Hide Caption 9 of 10 Photos: Canada's Justin Trudeau visits U.S. Trudeau greets students from Washington's Patterson Elementary School after he arrived at Andrews Air Force Base in Maryland on Wednesday, March 9. Hide Caption 10 of 10

Beyond the current pressing issues, it's a meaningful visit to Canada for Obama, not only as his last "Three Amigos" summit but also as a final-year return to the site of his maiden presidential foreign trip in 2009, when he flew Air Force One out of the country for the first time for meetings with then-Prime Minister Stephen Harper.

For one of the first times, the 54-year-old Obama found himself sharing a stage Wednesday with two leaders younger than him.

Fostering ties with the United States' two contiguous neighbors has never been Obama's top agenda item. He's focused instead on pivoting American foreign policy to the Asia-Pacific and managing various crises in the Middle East and Northern Africa.

While Wednesday's summit didn't come with the same high stakes Obama faces when he meets with NATO leaders in Warsaw next week, the meeting does carry significance for a president looking to cement his legacy.

To those ends, the leaders announced ambitious new agreements meant to curb climate change, a priority for Obama. That includes setting a target of producing half of the continent's power from renewable energy sources by 2025. Currently, the three countries together generate 37% of their power from clean energy sources like nuclear, wind, solar and hydro power.

JUST WATCHED Obama, Trudeau trade Bieber jokes Replay More Videos ... MUST WATCH Obama, Trudeau trade Bieber jokes 01:10

It's a breakthrough made possible by Trudeau's election a year ago; his successor Harper was a skeptic of global climate deals, and disagreements between Canada and the U.S. over the Keystone XL pipeline, which would have transported Canadian oil through the United States, led to an abrupt cancelation of the "Three Amigos" summit in 2015. After years of delays, Obama finally killed the deal last year.

While the burden of reaching the clean power target will fall on Obama's successor, the President's top climate adviser, Brian Deese, said market forces would also drive progress.

"I think that the transformation of the American energy sector that's underway is going to continue, and that has been driven by some of the policy choices that this president has made, but it's also being driven by market forces that are bringing down the cost of clean energy at rates that even the smartest analysts weren't predicting only a couple of years ago," Deese said.

The leaders also discussed plans to replace the much-maligned North American Free Trade Agreement with Obama's preferred TPP trade deal -- a measure that's faced fierce political opposition and is currently awaiting congressional approval. Obama is likely to attempt to reassure his counterparts the deal will eventually pass, though how and when remain unclear.

Both the Republican and Democratic presumptive nominees oppose the TPP, and 2016 candidates frequently have railed against free trade on the campaign trail. Republican Donald Trump has blamed the deals for flat wages and job losses, while Democrat Hillary Clinton reversed her support NAFTA, an agreement her husband secured as president.

Anti-trade sentiment helped drive the "Leave" campaign in Britain that backed the Brexit referendum, and even Obama has acknowledged recently that politicians must do more to help workers hurt by globalization.

Both Mexico and Canada are parties to the massive TPP, which is still awaiting approval from Congress. The Republican Senate Majority Leader Mitch McConnell has said he'll wait until November's general election to bring the 12-nation trade agreement of Pacific nations up for a vote. Trump on Tuesday said he would withdraw from the plan should it be approved by lawmakers.

"Our politicians have aggressively pursued a policy of globalization -- moving our jobs, our wealth and our factories to Mexico and overseas," he said during a speech in Pennsylvania. "Globalization has made the financial elite who donate to politicians very, very wealthy. I used to be one of them. Hate to say it, but I used to be one of them."