The race for the next governor of Missouri is between a Democrat who used to be a Republican and a Republican who used to be a Democrat in a nail-biter that’s polling within the margin of error.

It’s been an expensive and often bitter battle between Democratic attorney general Chris Koster and Republican political newcomer Eric Greitens.

Greitens, a former Navy SEAL officer, has focused his campaign largely on his military record, his work on his foundation The Mission Continues, and a pledge to fight corruption in the state's Capitol.

Koster, who describes himself as a conservative Democrat, was a two-term attorney general, and earned endorsements from the Missouri Farm Bureau and National Rifle Association, groups that typically support Republicans. He was first elected to public office nearly 22 years ago as a Republican. In 2007, he made the switch to the Democratic party.

The election has been the most expensive gubernatorial race in the country. According to figures from the media tracking firm Kantar Media/CMAG that were analyzed by the Center for Public Integrity, nearly $34 million was spent on broadcast TV ads in the race. Those figures do not include additional money spent on radio, online, direct mail or local cable TV ads, nor the cost of making the ads.

In the finals days leading up to Election Day, polls were showing differing results, placing the race squarely in toss-up territory.

A poll conducted in the week before the election by Public Policy Polling on behalf of Protect Missouri Families, a group that opposes “right-to-work” laws, showed Koster with 47 percent of the vote to Greitens’ 44 percent with a margin of error +/- 3.3 percentage points.

Another poll, conducted by Remington Research for The Missouri Times, showed Greitens at 46 percent to Koster’s 45 percent. That poll showed Libertarian candidate Spragins pulling in 2 percent and Fitz and Turilli each pulling 1 percent, with 4 percent undecided. That poll had a margin of error of +/- 2.4 percentage points.

A third poll, from Monmouth University, showed Greitens and Koster tied at 46 percent each.

The Associated Press and The (Springfield) News-Leader’s Will Schmitt contributed to this report.