Tester's win gave Democrats at least half the U.S. Senate, but the party still needed a victory in a tight Virginia race to gain control.
Burns, 71, first elected in 1988 as a folksy, backslapping outsider, has been under siege because of his ties to disgraced lobbyist Jack Abramoff and because of his own gaffes — including an incident in which he cursed at firefighters.
With 99 percent of precincts reporting, Tester had 198,032 votes, or 49.1 percent, to Burns' 194,904 votes, or 48.3 percent.
"One hundred thousand miles and 15 hours later, here we did it," Tester said Wednesday. "It is absolutely, critically important that we change the direction of the country.
"Now is the time to come together and put politics aside."
Burns declined to comment on the race as he left the Billings hotel where his supports were gathered, saying only that he was headed home to be near family.
If the margin of victory ends up within half of a percent, roughly 2,000 votes in the Senate race, Burns could request a recount.
Tester, 50, an organic farmer and state Senate president, rode a populist message and voter disgruntlement over corruption and the war in Iraq to victory. He portrayed himself as a Western moderate Democrat who owns guns, opposes gay marriage and has a libertarian's suspicion of the anti-terrorism Patriot Act.
The campaign was bitter and expensive from the start.
Tester hammered Burns for his ties to Abramoff and what Tester called the "culture of corruption" in Washington. Burns was a top recipient of campaign contributions from Abramoff, who pleaded guilty in January to corruption. He has since returned or donated about $150,000, and maintains he did nothing wrong and wasn't influenced by Abramoff.
Taking a page from Burns' book, Tester played the role of Washington outsider this time around.
He said he wanted to run the campaign his way — from Montana — and he relied on rallies with the state's popular governor, Brian Schweitzer, and Sen. Max Baucus.
Tester had surprised many in the state in June when he beat a better-financed and better-known Democrat in the primary.
But he also stood out in the field, with his scuffed cowboy boots and flattop haircut. One of his hands lacks three fingers, lost long ago in an accident with a meat grinder.
Burns was left with some of his lowest approval ratings of any election, while trying to fight one of his toughest opponents yet.
He tried to paint Tester as a liberal who wants to raise taxes and "cut and run" from Iraq, and focused his own campaign on his ability as a veteran senator to bring federal money to the state.
But Burns struggled with his image, including an embarrassing incident in late July when he confronted members of a wildfire-fighting team at the Billings airport, saying they had done a poor job, according to a state report and the U.S. Forest Service. The Hotshot crew had traveled from Virginia to help fight a fire east of Billings.