WASHINGTON — President Joe Biden planned to deliver a prime-time farewell address to the nation Wednesday, putting a capstone on his five-decade political career just days before he leaves an office he has long revered and is leaving only reluctantly.

The White House would not disclose what Biden planned to say ahead of his speech. But in his final months he has been seeking to cement a legacy as a transformative president that stabilized domestic politics while bolstering U.S. leadership abroad, one who ushered the nation out of a pandemic, made historic investments in infrastructure and clean energy, and worked to strengthen democratic institutions nationally and globally.

In a letter published early Wednesday before his address, Biden said the country was “stronger, more prosperous and more secure” than it was four years ago.

“It has been the privilege of my life to serve this nation for over 50 years,” Biden wrote. “Nowhere else on Earth could a kid with a stutter from modest beginnings in Scranton, Pennsylvania, and Claymont, Delaware, one day sit behind the Resolute Desk in the Oval Office as president of the United States. I have given my heart and my soul to our nation. And I have been blessed a million times in return with the love and support of the American people.”

“History is in your hands,” he added.

Whatever image the president was expected to project Wednesday evening, it would be set against a backdrop in which he is leaving office deeply unpopular and handing the reins to a successor, President-elect Donald Trump, whom he disdains and has repeatedly said is unfit to hold power.

Even the location of the speech, from behind the Resolute Desk, was a reminder that Biden is not departing as he may have wanted.

His last prime-time address delivered there was the 11 minutes he spent in July explaining why he dropped out of the presidential race under pressure from his own party as questions mounted about his age and fitness for another term.

Since Biden left the race and especially since Trump’s election victory in November, the president has struggled to maintain the spotlight.

“Farewell addresses are challenging because they aim to put the capstone on an era at a time when most of the country has already moved on to the next one,” said Robert Schlesinger, the author of the book “White House Ghosts: Presidents and Their Speechwriters.”

The farewell address, a tradition that dates back to President George Washington, is one of a series of speeches Biden is giving in his last days in office. By turns, he has highlighted domestic accomplishments, such as his “historic” conservation record. In an address focused on foreign policy at the State Department on Monday, Biden said he had fortified America’s place as a global leader and left it in a stronger position with allies and foes than it was four years ago. He will give at least two more speeches this week in which he is expected to continue building the case that as a one-term president, he made generational progress.

And in remarks as recently as last week, he has remained defiant about the presidential race, saying that he believed that he could have beaten Trump and that his decision to drop out was motivated by his desire to unify the Democratic Party.

“I think I would have beaten Trump, could have beaten Trump, and I think that Kamala could have beaten Trump,” Biden said.

Biden has told donors that he intends to stay involved in the party after he leaves office. Last week, when asked what role he planned to take on after his presidency, he responded: “I’m not going to be out of sight or out of mind.”

Previous presidents have used their farewell address to reflect on their records and warn of challenges ahead.

In 2001, President Bill Clinton used his farewell address to warn his successor not to diminish the country’s economic prosperity and global presence. In 2009, President George W. Bush delivered a somber address, where he acknowledged “setbacks” during his eight years in office, but said he hoped Americans understood that he did what he thought was right.

Before turning the reins over to Trump in 2017, President Barack Obama warned that economic inequity, racism and closed-mindedness threatened democracy and unity.

In his farewell address in 2021, Trump, politically isolated and facing impeachment after the attack on the Capitol by a mob of his supporters on Jan. 6, told supporters who had gathered to watch him take off from the tarmac at Joint Base Andrews: “Goodbye. We love you. We will be back in some form.”