Former Colorado governor John Hickenlooper prevailed in a tougher-than-expected Democratic primary Tuesday night to take on one of the Republicans’ most vulnerable Senate incumbents.

Hickenlooper, who gave up on a long-shot bid for president earlier this year, is expected to be a formidable opponent for Sen. Cory Gardner (R) in one of the few states Republicans are defending this year where President Trump lost four years ago.

Before Hickenlooper could train his eye on Gardner, though, he had to overcome a challenge on the left from former Colorado House speaker Andrew Romanoff, who was down 59.8 percent to 40.2 percent when Edison Research projected Hickenlooper the winner. When recruited by national Democrats to run for the Senate, the former two-term governor and onetime Denver mayor was widely seen as among the party’s best shots at picking up a seat in the chamber as it tries to wrest control from Republicans in November.

“Let me be clear: Change is coming, and you and I are going to bring it together,” Hickenlooper said in a video message in which he asked Romanoff’s supporters to bring their energy to his bid. “I’ve never lost an election in this state, and I don’t intend to lose this one.”

Romanoff said he called to congratulate Hickenlooper and urged all Democrats to unite to get him elected.

“I’m deeply grateful to everyone who supported our grassroots campaign; your friendship & your generosity mean the world to me. I just called John Hickenlooper to congratulate him — and to pledge my full support in his race against Cory Gardner. Please join me in doing the same,” he tweeted.

In the past month, Hickenlooper proved to be his own biggest obstacle, trying to fend off a pair of controversies — over ethics issues and racially insensitive comments — as he faced the challenge from Romanoff.

Some Democrats fret that the brewery owner turned politician will enter the fall stretch a weakened candidate. The closing weeks of the Democratic primary have been dominated by headlines about the stumbles of Hickenlooper, who entered the race after a Democratic presidential bid that never gained traction.

An independent ethics commission in Colorado said Hickenlooper violated state law on gifts when he was governor in 2018 by accepting rides on a private jet and, separately, in a Maserati limousine.

The commission, which was set up as part of an anti-graft law that Colorado voters approved more than a decade ago, fined him nearly $3,000 in early June for the luxury rides as he was traveling as governor. The commission also held him in contempt for not showing up for the first day of video hearings even though he was subpoenaed.

Hickenlooper has said he “takes responsibility” for the violations and pointed out that the allegations of wrongdoing were filed by a conservative organization. Hickenlooper’s supporters also say that the organization filed 97 claims, and 95 were dismissed. But an independent commission still agreed he violated two of the ethics rules while he was governor.

Hickenlooper also came under fire for recently resurfaced remarks he made in 2014 comparing elected officials to slaves being whipped aboard an “ancient slave ship.”

Hickenlooper apologized for the comments that circulated in a video on Twitter that showed him making a whipping gesture with his hand as he spoke of “the guy with the whip, and you’re rowing — we elected officials are the ones that are rowing, and they have nothing but hard, often thankless things to do.”

Republicans had seized on Hickenlooper’s troubles to argue that he’s unprepared for the general election.

“John Hickenlooper has learned the hard way after just a few weeks under pressure that never facing a tough race has left him unprepared, untested, and, as he’s said repeatedly, ‘not cut out to be a senator,’ ” National Republican Senatorial Committee spokeswoman Joanna Rodriguez said Tuesday.

The Senate seat is crucial to Democratic hopes of wresting the majority from Republicans, who hold a 53-to-47 advantage but are playing defense in more seats — 23 — including several in Democratic-leaning and swing states.

After his short-lived run for president in the past year, Hickenlooper was considered an ideal Senate recruit for Democrats — a well-known candidate and small-business owner who had won statewide races twice. He quickly secured the endorsement of the Democratic Senatorial Campaign Committee. In his recent ads, Hickenlooper emphasizes his record on job creation as governor.

But the controversies created an opening for Romanoff, another among progressive candidates trying to seize the mantle this year in races against establishment Democrats.

Romanoff had won the backing of several progressive groups, but unlike other liberal candidates who saw late surges elsewhere in the country, he had not been endorsed by many of the party’s national liberal luminaries such as Sens. Bernie Sanders (I-Vt.) and Elizabeth Warren (D-Mass.).

Sanders remained neutral, while Warren endorsed Hickenlooper, bolstering his standing among members of the party’s liberal wing.

Amber Phillips, Felicia Sonmez and Jennifer Oldham contributed to this report.