In his last State of the Union address, President Obama took shots at Republican presidential candidates, expressed one of his "few regrets," and said he's "as confident as I have ever been that the state of our union is strong." (Sarah Parnass/The Washington Post)

In his last State of the Union address, President Obama took shots at Republican presidential candidates, expressed one of his "few regrets," and said he's "as confident as I have ever been that the state of our union is strong." (Sarah Parnass/The Washington Post)

President Obama’s final State of the Union address Tuesday night wasn’t a speech to Congress. It was a sermon to the nation.

It wasn’t about policy prescriptions, really, or even about Obama’s record in office. It was a speech about one man whose name the president never uttered in the House chamber — Donald Trump — and the fear the nativist billionaire is stoking across the land in his bid for the Republican presidential nomination. Obama’s address was an extraordinary — and welcome — departure from the staid and ritualistic State of the Union format, and it showed how this president has grown in office.

“America has been through big changes before ,” Obama said near the beginning of his speech. “Each time, there have been those who told us to fear the future . . . promising to restore past glory if we just got some group or idea that was threatening America under control. And each time, we overcame those fears.”

The Trump theme built throughout the speech. Americans “need to reject any politics that targets people because of race or religion,” the president said, addressing one of Trump’s applause lines: “This isn’t a matter of political correctness. It’s a matter of understanding what makes us strong. The world respects us not just for our arsenal; it respects us for our diversity and our openness and the way we respect every faith.”

This was presidential leadership as it should be, and as Obama was reluctant to do early in his term: Using the power of his office to deliver a forceful moral message. Some may have thought it petty or unseemly that Obama was devoting a State of the Union address to the message of a candidate for the Republican presidential nomination. But in the current environment, there is nothing more important than answering the dangerous demagoguery that has arisen.

1 of 37 Full Screen Autoplay Close Skip Ad × The scene as Obama delivers his final State of the Union address View Photos Embarking on a final year in office, President Obama gave his seventh State of the Union address before a joint session of Congress. Caption Embarking on a final year in office, President Obama gave his seventh State of the Union address before a joint session of Congress. Jan. 12, 2016 President Obama enters the chamber to deliver his State of the Union address before a joint session of Congress. Melina Mara/The Washington Post Buy Photo Wait 1 second to continue.

In a pre-speech interview with NBC’s Matt Lauer, Obama said that if he could go back in time, “I think the most important thing I would say to an earlier version of myself would be to communicate constantly and with confidence to the American people.” He added: “The things I’ve done well during the campaign I have not always done well as president.”

Obama’s grasp of this crucial point was on display for the world Tuesday night, though the president, maddeningly cool and cerebral through much of his tenure, learned this important lesson far too late in his presidency. It’s tempting, even heartbreaking, to wonder how events might have turned out differently had Obama known then what he knows now.

Now Obama is deep into the lame-duck stage of his presidency, and he didn’t pretend otherwise. “I want to go easy on the traditional list of proposals for the year ahead,” he said at the start. He admitted that “expectations for what we’ll achieve this year are low,” and his specific prescriptions for legislation were relatively modest: criminal justice reform, fighting prescription-drug abuse, tax cuts for low-income workers.

He took some predictable shots at Republicans (“if anybody still wants to dispute the science around climate change, have at it — you’ll be pretty lonely”) and he boasted, equally predictably, about his record: “We’re in the middle of the longest streak of private-sector job creation in history. . . . Surveys show our standing around the world is higher than when I was elected to this office.”

But again and again, Obama returned to his unnamed target: a xenophobic showman who has been spreading fear and anger across the land toward immigrants, minorities, women, the disabled and, particularly, Muslims. “Will we respond to the changes of our time with fear, turning inward as a nation, and turning against each other as a people?” he asked.

Obama wasn’t offering a 10-point plan or demanding legislation on his desk. He was preaching. “Food stamp recipients didn’t cause the financial crisis; recklessness on Wall Street did,” he said. “Immigrants aren’t the reason wages haven’t gone up enough; those decisions are made in the boardrooms.”

The sermon was more effective because it came with some humility. He expressed his “regrets” that partisan rancor worsened on his watch. “There’s no doubt a president with the gifts of Lincoln or Roosevelt might have better bridged the divide.”

Obama meandered into a discussion of money in politics before resuming the night’s theme. “As frustration grows, there will be voices urging us to fall back into tribes, to scapegoat fellow citizens who don’t look like us, or pray like us, or vote like we do, or share the same background,” he said. “We can’t afford to go down that path. . . . It contradicts everything that makes us the envy of the world.”

The president was late to find his moral voice, but it was important that he spoke.

Twitter: @Milbank

Read more from Dana Milbank’s archive, follow him on Twitter or subscribe to his updates on Facebook.