Democrats lost one of their last bastions in the American south on Tuesday as businessman Matt Bevin was elected only the second Republican governor of Kentucky in the past 40 years.

Bevin edged out Democratic state attorney general Jack Conway by a margin of 52% to 44% with over 90% of precincts reporting in what was one of the most closely watched elections of 2015. Libertarian Drew Curtis, the founder of Fark.com, received just 4%.

Despite having trailed in the polls for months before Election Day, Bevin managed to eke out a victory in a state that has long trended conservative. Barack Obama lost the state by a margin of 60% to 37% in 2012 and the last Democratic presidential candidate to carry the state was Bill Clinton. However, Democrats had maintained a foothold in state-level politics. The state has only elected one Republican governor in the past 40 years and the state house of representatives is the only state legislative chamber still held by Democrats in the entire south.

Bevin’s win was particularly noteworthy as it came in one of the rare places where Obama’s health care law has been overwhelmingly popular. The state’s health insurance exchange, Kynect, has been considered perhaps the most successful of the health insurance exchanges set up under the Affordable Care Act. However, Bevin has pledged to dismantle Kynect as well as overturn the state’s expansion of Medicaid if elected.

The two candidates also went back and forth over Kim Davis, the Kentucky county clerk who received national attention this summer for refusing to issue marriage licenses to same-sex couples. While Bevin supported Davis’s stand, Conway supported the judicial decision to force the county clerk to issue licenses. The resulting controversy is being used as a wedge issue by Republicans to turn out their social conservative base.

Bevin was a surprise winner in the GOP primary by a razor-thin margin of 86 votes. The tea partier had been persona non grata in the Kentucky Republican Party after mounting a primary challenge to current Senate majority leader Mitch McConnell in 2014 during which he accused McConnell of being insufficiently conservative. McConnell eventually won by 25 percentage points after a bitter and hard-fought contest, which included Bevin being embroiled in a cockfighting scandal.

In the general election, Conway’s campaign focused on depicting Bevin as untrustworthy while Republicans pushed back to try to tie the Democratic candidate to the overwhelmingly unpopular Obama. One national Republican strategist familiar with the race thought that, in a close race, that would be enough. “The mood in Kentucky is too anti-Obama and too-anti Democrat,” the strategist said. It looked as if a late advertising blitz mustered on Bevin’s behalf may helped close the gap sufficiently for Republicans to be carried home by a conservative electorate in the Bluegrass State.

Bevin’s win also had coat tails down ballot as Democratic state auditor Adam Edelen, widely tipped as a potential opponent for Senator Rand Paul in 2016, lost in an upset to his Republican opponent. Edelen’s defeat removes a major political threat to Paul and clears the way for the first-term Kentucky senator to continue to campaign for the White House without jeopardizing his Senate seat.

In a statement, Tennessee Governor Bill Haslam, who chairs the Republican Governor’s Association, said: “Matt Bevin’s election tonight marks a fresh start for Kentucky … Under Bevin’s leadership Kentucky will prosper with a new direction and enjoy the success that comes from having the leadership of a Republican governor. The RGA is proud to congratulate Governor-Elect Matt Bevin on his victory.”

In contrast, Elisabeth Pierson, the executive director of the Democratic Governor’s Association, cast the blame on Donald Trump. “Attorney General Jack Conway ran a strong campaign focused on the issues that matter to Kentuckians: good schools, good-paying jobs and economic opportunity … unfortunately he ran into the unexpected headwinds of Trump-mania, losing to an outsider candidate in the Year of the Outsider. While Jack Conway came up short tonight, his presence in this race strengthened the issues debate in Kentucky.”

The defeat marked Conway’s second loss in a major statewide election. Prior to running for governor he was the Democratic nominee for the Senate in 2010 where he lost to Rand Paul in an ugly race that saw him attack Paul’s Christian faith in an infamous “aqua Buddha ad”. The television commercial backfired and Paul ended up winning comfortably over his Democratic opponent by a margin of 56% to 44%.