The prime minister spoke of his friend Barack as a role model.

"History books will record the signature policies," Justin Trudeau said. "What I will remember — what I hope we all remember — are the lessons he taught us not by executive order, but by example."

Seated in the centre aisle beside Sophie Gregoire Trudeau, the U.S. president appeared humbled as the prime minister paid tribute.

"That we are accountable to each other. That we are stronger together than we are apart. That we are more alike than we are different," Trudeau said. "And that there is a place in this world for politics that is hopeful, hard-working, ambitious and kind."

These are, of course, all qualities the young prime minister wants to be associated with himself, just as he is no doubt happy to be associated with the president, but also just as he might be seen to be a successor to Barack Obama's style and agenda.

When the president himself took the podium, he cheered the "new hope" and "new energy" of the prime minister. And he joked, as he has, about the greying of his own hair.

Obama's exit in sight

The political force of 2008 has carried the burden of the presidency for nearly eight years. His exit is in sight and he is now competing for attention with the contest to replace him.

Obama is still gifted and at ease, able to joke and analyze and preach (bringing out little murmurs of agreement from the assembled). He is an orator in the fine American tradition.

He will also depart with a record of some achievement, possibly with lasting import: on health care, the environment, the economy, clean energy, education and gay rights. All that above and beyond the singular, historic achievement of his election as the first black president of a nation that endorsed slavery, with all of the profound and lasting significance that goes with that.

But in his waning moments he is faced with the antithesis of what he has strived to represent. In Donald Trump, he is confronted with the possibility of being followed by his exact opposite.

He has come to feel the need to respond, and this speech, on friendly and advantageous soil, would be, in part, about all that and everything else that might be pursued instead, even if the spectre was never named.

U.S. President Barack Obama addresses a joint session of Parliament after the Three Amigos summit in Ottawa. 1:18:53

The hope and fear of change

The man who promised change, here acknowledged the fear and uncertainty that change can bring.

The world is more peaceful and interconnected, but newly threatened by terrorism. The world is more prosperous, but globalization and technological change have come with rising inequality and stagnation.

"If the benefits of globalization accrue only to those at the very top, 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.

"Politicians, some sincere and some entirely cynical, will tap that anger and fear, hearkening back to bygone days of order, 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."

Having famously rejected the distinction between blue states and red states, he has become a president who rejects overly simple positions.

He lamented the inequality that sees a CEO earn more in a day than a worker earns in a year, and the New Democrats in the House enthusiastically applauded. A few breaths later he dismissed those who reject globalization and free trade and the New Democrats were noticeably less enthused.

On security, he said there are times when unilateral action is necessary, but that multilateralism is best, and also that disputes are best resolved with peaceful diplomacy. He pushed for Canada to fully contribute to NATO, and four Conservative MPs stood to applaud.

Moments later it was Liberals and New Democrats quickly standing to applaud as he stressed the need to combat climate change and congratulated the province of Alberta on its progress in this regard.

Obama: 'The world needs more Canada' 1:21

How a country is built

Then to the values of diversity and plurality; of gay rights and women's rights and, to great applause, the rights and contributions of Muslims.

"We have to stand up against the slander and the hate levelled against those who look or worship differently. That is our obligation," he said. "That is who we are. That is what makes America special. That is what makes Canada special."

He spoke eloquently of the immigrant and the refugee and smartly told the story of Maryam Monsef, the young woman who fled Afghanistan as a child and is now the minister of democratic institutions.

The president had quoted and repeated the prime minister's father, Pierre Trudeau — "A country, after all, is not something you build as the pharaohs built the pyramids, and then leave standing there to defy eternity. A country is something that is built every day out of certain basic shared values" — and, from certain angles, there is a resemblance.

Both were scholars, each, in their own ways, stood apart. And, as Senate Speaker George Furey would later say, the president has "stood tall for the power of reason over passion."

(He quoted and recalled, as well, the words of Martin Luther King Jr., a man who sought justice without violence.)

Of course, the president has not succeeded in bringing reasonableness to the American political system. What swirls around him is perhaps even less reasonable than what was there before he arrived.

Soon he will leave the stage, to see whether his country's politics comes to sound more like him or something like the unnamed subject of his remarks, to see what lasting influence he has had on whoever follows in the years ahead.

Amid all the tumult of the last year, it is perhaps useful to note, as others have, that his public approval is back above 50 per cent.

"As we go forward together, on that freedom road, let's stay true to the values that make us who we are," he said, bidding adieu to this country, "Canadians and Americans, allies and friends, now and forever."

From the galleries there came a chant for four more years.