Alaska Senator Lisa Murkowski has won re-election, defeating a Republican candidate backed by the Tea Party.
Ms Murkowski was defeated in August for the party nomination by Joe Miller, who had been endorsed by ex-Governor Sarah Palin.
Ms Murkowski told supporters to write her name on the ballot, and is the first candidate to win a so-called write-in bid for Senate since 1954.
Officials said she was ahead by 10,000 votes with only 700 left to count.
Failed ballot challenges
The result comes after weeks of hand counting, and legal squabbling and manoeuvring by Mr Miller's camp, which sought to challenge ballots in which Ms Murkowski's name was misspelled or unclear.
The election was held on 2 November.
It was unclear whether Mr Miller would continue pressing his challenging in court. In recent weeks many lawyers who had travelled to Alaska for the fight have departed.
Analysts have described her victory as a rebuke for Ms Palin, the 2008 Republican vice-presidential candidate and Tea Party figurehead. She has been openly at odds with Ms Murkowski since defeating her father Frank Murkowski to win the state governorship in 2006.
The defeat shows Ms Palin's endorsement could not even deliver a victory in her home state, which votes heavily Republican, analysts said.
Mr Miller, a lawyer, former judge and former US Army officer, rode a surge of anti-incumbent Tea Party enthusiasm to win the August Republican party primary.
But his campaign subsequently suffered from revelations that as a government lawyer he had been disciplined for improperly using government computers for partisan political purposes.
Later, private security guards working for his campaign handcuffed a journalist who was asking questions he had refused to answer.
Meanwhile, Ms Murkowski, chastened by her surprise primary defeat, launched an energetic write-in campaign that included songs instructing supporters on the proper spelling of her name.
The last senator to win a write-in campaign was Strom Thurmond in 1954.