PHOENIX—Independent presidential candidate Robert F. Kennedy Jr.said he would suspend his election bid and endorse Donald Trumppotentially boosting the Republican former president just after Democrats left their convention with renewed hope for a win.

“I promised the American people that I would withdraw from the race if I became a spoiler,” Kennedy said at a rally here Friday. “In my heart, I no longer believe that I have a realistic path to electoral victory in the face of this relentless, systematic censorship and media control.”

In explaining his decision to back Trump, Kennedy said that the principles that persuaded him to leave the Democratic Party and run as an independent now led him to back the former president. He cited protecting free speech, among other examples.

Polls indicate that Kennedy’s departure will likely help Trump, providing some welcome news for a candidate who has struggled to counter the momentum of his Democratic opponent, Vice President Kamala Harris. Her entrance into the race last month in place of President Biden has turned the election on its head. She now is ahead in many national polls and posting better numbers in vital battleground states.

At the rally, Kennedy suggested that Trump, with whom he has spoken to in recent weeks, had asked “to enlist me in his administration.” He said he tried to meet with Harris and she declined.

Representatives for Trump and Harris didn’t immediately respond to requests for comment.

Kennedy’s announcement came after increasing speculation about the purpose and viability of his run. Kennedy, an environmental lawyer who is the son of liberal icon Sen. Robert Kennedy, was unable to build on an initial surge of interest in his campaign—despite polls showing significant voter dissatisfaction with the Democratic and Republican slates. The campaign faced hurdles in qualifying for state ballots and was hit by a series of minor scandals that undercut Kennedy’s run.

On Friday he said he would remove his name from the ballot in competitive battleground states—but leave it on others, letting voters back him in solid blue or solid red states where he wouldn’t affect the outcome.

Democrats feared from the outset that Kennedy would act as a spoiler, shaving off support for Biden in what was expected to be a tough rematch with Trump. In 2000, third-party candidate Ralph Nader was blamed by Democrats for Republican George W. Bush’s defeat of Democrat Al Gore by winning significant votes in Florida.

Biden’s decision last month to exit the race upset that equation, and polls showed many Democratic-leaning voters in recent weeks abandoned Kennedy and returned to the party fold after Harris became the nominee. That left mostly dissatisfied Republicans in the Kennedy column—who now may be inclined to come home to Trump.

Kennedy and his running mate, Nicole Shanahan, pitched themselves as unity candidates who could bring together a polarized country. Shanahan suggested publicly earlier this week that the pair might end their bid and join with Trump to prevent Harris from becoming president. Trump praised Kennedy after the comments and said he would be honored to receive an endorsement, while acknowledging they have different positions and opinions on some issues.

Kennedy, age 70, originally began running for president last year as a Democrat to challenge Biden, saying he wanted to “end the corrupt merger of state and corporate power that is threatening now to impose a new kind of corporate feudalism” in America. When that proved unsuccessful, he switched to running as an independent. Polls showed him picking up voters who were dissatisfied with the 2020 rematch of Biden and Trump, at times showing him with more than 10% support nationally.