OTTAWA — U.S. President Barack Obama brought the House down as he passed a diplomatic torch of sorts to Canadian counterpart Justin Trudeau, along with a pointed warning about the perils of injustice and inequality.

In what was almost certainly his last visit to Canada as president, Obama held court Wednesday for nearly an hour before a joint session of the House of Commons and the Senate, basking in cascades of applause and heaping praise on the country's young new prime minister, with whom he's become fast friends.

But he also made a point of mentioning a close connection to the Hamilton area.

"We're linked by the ties of friendship and family. In my case, an outstanding brother-in-law in Burlington," Obama said. "I give Burlington a shout-out."

He was referring to Konrad Ng, who is married to Obama's sister Maya Soetoro and grew up in Burlington. Obama, before he became president, visited Burlington in August 2004 to mark the couple's marriage. Ng took Obama and his family to Spencer Smith Park.

Trudeau, said Obama, has brought new energy and leadership to Canada and to the everlasting alliance between the two countries. The world will continue to benefit from Trudeau's time in office, he said, even as his own era comes to an end.

But even as he lauded his host country for championing values like integrity, human rights and fair play, he urged it to pay its full share to NATO — a solitary note of discord in a speech focused on Canada-U.S. harmony.

"As your ally and as your friend, let me say that we'll be more secure when every NATO member, including Canada, contributes its full share to our common security," Obama said.

Canada has committed to meeting a standard target of spending two per cent of its GDP on defence, but has been lagging well below that mark for several years.

"The world needs more Canada, NATO needs more Canada. We need you."

That direct request sets the stage for the next time Trudeau and Obama are likely to cross paths — next month's NATO summit in Poland.

And just as he did during a news conference with Trudeau and Mexican President Enrique Pena Nieto earlier in the day, Obama also warned against the perils of protectionism and xenophobia, which he hinted are closer than some might think.

"If our democracies seem incapable of assuring broad- based growth and opportunity for everyone, then people will push back out of anger or out of fear," he said.

"And politicians — some sincere and some entirely cynical — will tap that anger and fear, hearkening back to bygone days of order and predictability and national glory, arguing that we must rebuild walls and disengage from a chaotic world, or rid ourselves of the supposed ills brought on by immigrants, all in order to regain control of our lives."

Trudeau introduced Obama with words of praise and a nod to the president's final months in office.

"History books will record signature policies, (but) what I will remember — what I hope we all will remember — are the lessons you taught us not by executive order, but by example."

Obama's speech was full of the requisite jokes about hockey, Canadian celebrities taking over Hollywood, Canada's weather and the perils of high office — his hair has turned so grey, he said, his wife calls it the "Great White North."

"We can all agree that our democracies are far from perfect, they can be messy and they can be flawed, and they can leave all sides of a debate unsatisfied," he said.

Loading... Loading... Loading... Loading... Loading... Loading...

Both countries, he said, must do more to live up to the ideals they offer and fight back when responses to legitimate fears result in some people being turned into scapegoats.

"We have to call this mentality what it is: a threat to the values we profess, the values we seek to defend."

Obama was greeted by a sustained standing ovation and cheers as he entered the House of Commons, shaking hands with cabinet ministers as he took his seat. The ovations continued to thunder around him throughout his speech, extending it to nearly an hour.