The months Rep. Mike Coffman (R-Colo.) spent attempting to distance himself from his party’s presidential nominee paid off on Tuesday, when he held on to his congressional seat in what was expected to be a nail-biter of a race against Democrat Morgan Carroll.

To defeat Carroll, a Colorado state senator, Coffman had to win over some voters who supported Democratic presidential nominee Hillary Clinton, who won the state of Colorado and some of the counties that include parts of Coffman’s district. He also had to sever his ties with GOP presidential nominee Donald Trump, the victor nationwide and now president-elect.

Coffman ended up winning about 52 percent of the vote, while Carroll took about 43 percent, according to The Associated Press as of Wednesday morning. Another 5 percent went to Libertarian candidate Norm Olson.

“For months now, pundits declared this race nearly impossible for me to win,” Coffman said in a speech Tuesday evening. “The environment is too tough,’ they said. ‘Republicans are divided,’ they said. Tonight, we proved them wrong.”

The race in the Denver suburbs gained national attention and money. Democrats saw 2016 as a chance to tie Coffman to Trump and pick up the congressional seat, which Coffman took over from another Republican in 2008. Republicans wanted to prove they could maintain a hold on the district in spite of demographic changes favorable to Democrats.

Coffman was one of the Republicans who tried hardest to disassociate themselves from Trump. He released an ad in August that featured him saying he didn’t “care for [Trump] much.” Coffman called for Trump to “step aside” in October, and then eventually said he would not vote for him, although he also said he would not support Clinton.

Coffman has reshaped his image as the district changed, in the process offering a model for how Republicans can behave to win over Latino voters. Thanks in part to redistricting, the population that Coffman represents is now 20 percent Latino. He was once a hard-liner on immigration in the tradition of his predecessor, former Rep. Tom Tancredo (R-Colo.), but more recently he has tried to learn Spanish and has supported some immigration reform measures.

But Carroll frequently attempted to tie Coffman to Trump’s positions, including those regarding immigration and those that cast doubt on President Barack Obama’s birthplace.

Coffman said in 2012 that “in his heart, [Obama] is not an American” ― a remark redolent of Trump’s long campaign to discredit the president as non-American. Coffman apologized when his comments were made public. Coffman’s immigration positions, meanwhile, are not actually similar to Trump’s ― he has talked about the need for enforcement, but he, unlike Trump, has said certain undocumented immigrants should be allowed to remain in the country.

Coffman and his associates tried to paint Carroll as a partisan who would blindly support Clinton. The National Republican Congressional Committee ran multiple ads that Politifact called misleading, claiming that Carroll was responsible for Colorado’s debt and spending, and that she opposed tracking sexual predators.

Both candidates pulled in the big guns. Sen. Bernie Sanders (I-Vt.) campaigned for Carroll on the weekend before the election, and Obama endorsed her.

Coffman, meanwhile, campaigned with House Speaker Paul Ryan (R-Wis.). He also got a boost from Americans for Prosperity, the conservative political advocacy group funded by the Koch brothers, which did not endorse him, but which organized against Carroll.

Carroll said that her loss was “tough.”

“This isn’t the outcome we were expecting, a lot of us,” she said in a concession speech Tuesday evening. “I will never regret [running], and I will not stop fighting for all the things we stood for in this campaign.”