Former U.S. President Barack Obama and former Vice-President Joe Biden made a surprise visit to the Invictus Games in Toronto, where the pair sat alongside Prince Harry at a wheelchair basketball game.

The president and the prince took time to meet with participants before the U.S- France game, held Friday afternoon at the Toronto Pan Am Sports Centre in Scarborough.

U.S. participant Isaac Rios said it was “one of the greatest things” to speak with Obama.

“It was amazing for him to take the time to be here with us and actually sit down and speak to us, shake our hands,” Rios told CTV Toronto.

“And Prince Harry was amazing. He came down there, very down to Earth, gave us all hugs and joked around a little bit with us, got us amped up.”

Obama was in town for a sold-out speaking event at the Metro Toronto Convention Centre. The lunch event came one day after former U.S. Secretary of State Hillary Clinton gave her own speech in Toronto, to promote her new book.

In a question-and-answer period with former U.S. ambassador to Canada Bruce Heyman, Obama discussed the challenges of his presidency, the Paris Accord, how the “new information era” has changed politics and why diplomacy is needed more than ever to address the threat of North Korea’s nuclear arsenal.

While he didn’t go as far as calling out U.S. President Donald Trump, Obama said that protectionist policies will do little to advance U.S. industries in an age of artificial intelligence.

"You'll still see auto companies doing pretty well and you'll see us manufacturing the goods that we use in the United States or Canada, but you'll walk through those factories and they'll be empty because they'll be run by robots and AI," Obama said.

"The biggest challenge that we face in terms of maintaining good manufacturing jobs in our countries come from automation, and that is going to accelerate."

Obama also recounted his historic presidential bid in 2008 and credited young people with propelling him to victory.

"The reason I won was because I trusted young people, and trained them, to go into communities and do amazing work," Obama said.

The event, organized by Ottawa-based think tank Canada 2020, drew a crowd of approximately 3,000, including Ontario Premier Kathleen Wynne and Toronto Mayor John Tory.

Ontario NDP Leader Andrea Horwath said it was interesting to see leaders from many political backgrounds in the audience.

“I can tell you, if we all left here as politicians saying, ‘Well, let’s just work on all the things Obama gave us as instructions,’ then things would be pretty boring in politics because there would be no differences,” Horwath said.

Tickets were sold for $1,000 each. Attendee Rosemary Mercury said she would’ve paid “five times over” for the chance to see Obama.

“He epitomizes compromise. And everything that comes out of his mouth is inspiring to me,” she told CTV Toronto.

A group of teenagers skipped school on Friday, hoping to catch a glimpse of Obama outside the convention centre.

“Knowing that there’s even a slight little chance that I’d be able to see him, it’s all worth it,” one of the girls said.

The speaking engagement marked Obama’s second visit to Canada since leaving the White House. Earlier this year, he spoke at an event in Montreal, where he later went out to dinner with Prime Minister Justin Trudeau.

Another former commander-in-chief will visit Toronto next week, with Bill Clinton giving a talk at the Fairmont Royal York Hotel on Oct. 3.

Obama’s speech was closed to the media, but Canada 2020 tweeted excerpts of his comments.

With files from CTV Toronto, The Canadian Press and The Associated Press