By MATT GOURAS
HELENA, Mont. (AP) -- U.S. Sen. Jon Tester prevailed Wednesday in a tight re-election battle, beating back nearly two years of attacks for his support of some Obama administration policies and handing U.S. Rep. Denny Rehberg his first election loss since 1996.
The two campaigns, and their third-party allies, flooded Montana airwaves with unprecedented spending on attack ads as both parties considered the race crucial for control of the U.S. Senate. Democrats kept their majority in the Senate on Tuesday, with victories in senate races in other states. A third of the chamber's seats were up for election.
The Big Sandy farmer rode to victory on his everyman appeal and workman-like approach to the job despite a political environment that Republicans felt favored them. Rehberg had gambled the time was ripe for Republicans to take back a Senate seat his friend Conrad Burns only narrowly lost six years ago to Tester.
Like then, this race was tight. Tester held a narrow lead with most of the vote counted early Wednesday. The most expensive race in state history ensured that the race finished as close as it started.
But the Democrat prevailed by doing even better in urban areas like Butte than in 2006, and closing the gap in many rural areas.
Tester, unlike six years ago, carried his very rural home of Choteau County. The Tester campaign had relentlessly attacked Rehberg for filing a lawsuit against the Billings city fire department for a wildfire on his land.
Another key development was the performance of Libertarian Dan Cox, who was pulling in more than 6 percent of the vote according to early returns -- much of it likely coming from Rehberg's conservative flank.
The bitter battle between Tester and Rehberg dominated Montana politics for nearly two years. Rehberg abandoned a safe congressional seat he had held for more than a decade to take on Tester. Money flowed into the state in record levels -- much of it tying Tester to President Barack Obama.
Tester insisted all along the tactic wouldn't work, arguing Montanans would appreciate the substance he brought to the job in searching for solutions to tough problems like health care for veterans and farm programs for rural areas.
Tester mixed and mingled all night in a party-like atmosphere at a Great Falls convention room before going to bed at around 2 a.m. after speaking to cautiously optimistic supporters.
"As you know six years ago we were in a very similar situation," Tester said. "Quite frankly, before this night started, we thought we were gonna be in this situation where the votes were gonna be coming in throughout the night."
The mood was starkly different at a Rehberg event in Billings, where most supporters had left by midnight. Rehberg had not made one appearance all evening long -- and reporters outnumbered supporters before the bunting was pulled down and campaign operatives retreated in hope that the numbers would shift their direction.
Rehberg accused Tester of failing to live up to an original promise of independence by voting with Obama on many key issues.
Tester had a more complex message for voters.
The Democrat touted his work for Montana constituents while promising to make a stalled bipartisan budget and tax deal his top priority if re-elected. At the same time, Tester attacked Rehberg as a selfish career politician with few results to show for it.
During the final week or so of the campaign, Tester allies unapologetically aired an advertisement that sought to convince conservatives to vote for Cox over Rehberg.
Tester, previously a state senator, before he was elected to the U.S. Senate in 2006. This year's race marked Rehberg's second run at the Senate. He fell short in a 1996 challenge to Baucus.
Copyright 2012 The Associated Press.