Sen. Jon Tester held off challenger Matt Rosendale in a razor thin election that ended Wednesday, keeping the seat he first won in a political upset 12 years ago against former Sen. Conrad Burns.

The race, which remained too close to call well into Wednesday, was called by the Associated Press at around 11 a.m. with Tester at 218,145 votes to Rosendale's 213,934.

“We did it,” Tester told a gathering in Great Falls. “Thousands of people have spent incredible amounts of their free time to walk around this state and talk about how important this race was.”

Vying for his third term, the Big Sandy farmer ran a campaign firmly rooted in health care, public lands, campaign finance reform and veterans issues, and he successfully defended attacks from Rosendale and President Donald Trump, who visited the state a record four times.

Trump boasted on Wednesday that the candidates he supported had “great success.” That was true in some states, including Missouri, where Democratic incumbent Claire McCaskill lost her seat, along with Heidi Heidcamp in North Dakota.

But Democrat Jacky Rosen unseated GOP incumbent Dean Heller in Nevada, and in Montana, Tester held his seat despite a parade of Republican opponents working to unseat him. They included Sens. Lindsey Graham and Rand Paul, Vice President Mike Pence and the president's own son, Donald Trump Jr.

“I can tell you we need to work together in this country,” Tester said. “That's what made this country great, is people working together. Not just Democrats, but Republicans, Independents, Libertarians, all working together the same way my grandparents did.”

Tester's victory was propelled by the state's urban and more liberal leaning centers, including Bozeman, Helena, Great Falls, Indian Country and Missoula. It's there where Tester garnered enough votes to compensate for rural counties that overwhelmingly went for Rosendale.

Tester bested Rosendale by more than 12,000 votes in Missoula County. Across the state, women voters also went heavily for Tester at 59 percent, while 39 percent went for Rosendale, according an Associated Press poll.

“We need to hold people accountable for their actions, and that will be done,” Tester said. “And we need to make sure we move forward in a way that we have the strongest middle class ever.”