Attorney General Andy Beshear celebrated his win in the Democratic primary for governor Tuesday night | Photo by Jeremy Chisenhall

Attorney General Andy Beshear won a competitive Democratic primary race for governor Tuesday night, earning his party’s nomination to take on incumbent Republican Gov. Matt Bevin this fall — and adding another chapter in the heated rivalry between the two politicians.

Bevin also won his party’s nomination in the Republican primary Tuesday night, though he struggled to gain a majority of the votes in a race that was much closer than expected.

The Associated Press called the race for Beshear shortly before 8:45 p.m. when 91% of precincts statewide had reported their results, showing the attorney general with nearly 38% of the vote. Beshear was followed by House Minority Floor Leader Rocky Adkins with 33% of the vote, while Adam Edelen was in third with 27%.

Beshear won the state’s two most populous counties — Jefferson and Fayette — by wide margins, in addition to winning big in northern Kentucky and most rural counties in western Kentucky.

Rocky Adkins made a strong showing in the eastern Kentucky region that he calls home, winning a number of those counties by blowout margins, though he finished far behind Beshear and Edelen in Louisville and Lexington.

Edelen — whose campaign far outspent both Beshear and Adkins, along with a super PAC supporting him — finished roughly 8 percentage points behind Beshear in both Lexington and Louisville, only placing first in Meade County and Breckinridge County.

The Associated Press called the race for Bevin  just before 8 p.m. when 53% of precinct returns were in statewide, showing him with only 50.8% of the vote in the Republican primary for governor, trailed by state Rep. Robert Goforth with 40.8%.

Despite Goforth’s minimal campaign and low name recognition as a freshman member of the state House, he beat Bevin in 31 counties in the mountain region of eastern Kentucky and the south, some by blowout margins. His success against Bevin perhaps lends credence to recent polling in the state showing that roughly one third of Republicans have an unfavorable view of the governor’s performance.

Bevin finished the night with 52% of the vote, while Goforth netted 39%. Republicans Williams Woods and Ike Lawrence  received 5 and 3% of the vote, respectively.

In his acceptance speech, Beshear contrasted himself with Bevin my criticizing the governor’s rhetoric against teachers and public employees, saying that he will “restore honesty, decency and transparency” to Frankfort.

Adkins and Edelen both said in their concession speeches that they will support and campaign for Beshear in the fall in his race against Bevin.

The showdown between Beshear and Bevin in November will serve as a continuation of the war of words between the two politicians over the past three and a half years. Beshear has repeatedly challenged the Bevin administration in court over the constitutionality of his executive orders, while the governor has characterized the attorney general and his father — former Gov. Steve Beshear — as corrupt and incompetent.

This story has been updated.