HELENA, Mont. (AP) — U.S. Sen. Jon Tester has won a second term, fending off a challenge from Republican U.S. Rep. Denny Rehberg.

Tester and Rehberg had been in a close contest for nearly two years as each struggled to break the race open despite a dizzying number of attack ads.

Tester ran a campaign touting his work to help Montana. Throughout, he attacked Rehberg as a career politician who had few results to show for it.

Tester survived Rehberg's relentless attacks tying him to unpopular Obama administration policies.

Rehberg is a six-term congressman who will leave office at year's end.