(Adds Jibril comments on Gaddafi death, edits)
* Gaddafi killed as last bastion in hometown overrun
* Libyan PM says Gaddafi shot after taken into custody
* Formal "liberation" expected to be declared Saturday
* New leaders, Western backers hail dawn of new Libya
* Challenge now to impose order on array of armed groups
By Rania El Gamal and Tim Gaynor
SIRTE, Libya, Oct 20 Muammar Gaddafi was killed by Libyan fighters he once scorned as "rats", cornered, beaten and then shot in the head after his chaotic capture by fighters who overran his last redoubt on Thursday in his hometown of Sirte.
Two months after Western-backed rebels ended 42 years of eccentric, often bloody, one-man rule by capturing the capital Tripoli, his death and the fall of the final bastion ended a nervous hiatus for the new interim government, which is now set to declare formal "liberation" with a timetable for elections.
U.S. President Barack Obama, in a veiled dig at the Syrian and other leaders resisting the democrats of the Arab Spring, declared "the rule of an iron fist inevitably comes to an end".
But confusion over Gaddafi's death was a reminder of the challenge for Libyans to now summon order out of the armed chaos that is the legacy of eight months of grinding conflict.
The killing or capture of senior aides, including possibly two sons, as an armoured convoy braved NATO air strikes in a desperate bid to break out of Sirte, may ease fears of diehards regrouping elsewhere - though cellphone video, apparently of Gaddafi alive and being beaten, may inflame his sympathisers.
Libyan Prime Minister Mahmoud Jibril, reading what he said was a post-mortem report, said Gaddafi was hauled unresisting from a "sewage pipe". He was then shot in the arm - it was not clear by whom - and then put in a truck which was "caught in crossfire" as it ferried the 69-year-old to hospital.
"He was hit by a bullet in the head," Jibril said, adding it was unclear which side had fired the fatal shot.
The body, bloodied, half naked, Gaddafi's trademark long curls hanging limp around a rarely seen bald spot, was delivered, a prize of war, to Misrata, the city west of Sirte whose siege and months of suffering at the hands of Gaddafi's artillery and sniper made it a symbol of the rebel cause.
A quick, secret burial was planned, officials said.
"It's time to start a new Libya, a united Libya," Jibril declared. "One people, one future." A formal announcement of liberation, which will set the clock ticking on a timeline to elections, would be made on Saturday, Libyan officials said.
French President Nicolas Sarkozy, who spearheaded a Franco-British move in NATO to back the revolt against Gaddafi hailed a turn of events that few had expected so soon, since there had been little evidence that Gaddafi himself was in Sirte.
But he also alluded to fears that, without the glue of hatred for Gaddafi, the new Libya could descend, like Saddam Hussein's Iraq, into bloody factionalism: "The liberation of Sirte must signal ... the start of a process ... to establish a democratic system in which all groups in the country have their place and where fundamental freedoms are guaranteed," he said.
NATO, keen to portray the victory as that of the Libyans themselves, said it would wind down its military mission.
SHOT IN HEAD
The circumstances of the death of Gaddafi, who had vowed to go down fighting, remained obscure. Jerky video showed a man with Gaddafi's distinctive long, curly hair, bloodied and staggering under blows from armed men, apparently NTC fighters.
The brief footage showed him being hauled by his hair from the hood of a truck. To the shouts of someone saying "Keep him alive", he disappears from view and gunshots are heard.
"While he was being taken away, they beat him and then they killed him," a senior source in the NTC told Reuters before Jibril spoke of crossfire. "He might have been resisting."
Officials said Gaddafi's son Mo'tassim, also seen bleeding but alive in a video, had also died. Another son, heir-apparent Saif al-Islam, was variously reported to be surrounded, captured or killed as conflicting accounts of the day's events crackled around networks of NTC fighters rejoicing in Sirte.
In Benghazi, where in February Gaddafi disdainfully said he would hunt down the "rats" who had emulated their Tunisian and Egyptian neighbours by rising up against an unloved autocrat, thousands took to the streets, loosing off weapons and dancing under the old tricolour flag revived by Gaddafi's opponents.
Mansour el Ferjani, 49, a Benghazi bank clerk and father of five posed his 9-year-old son for a photograph holding a Kalashnikov rifle: "Don't think I will give this gun to my son," he said. "Now that the war is over we must give up our weapons and the children must go to school.
"But Gaddafi was a terrible dictator and this was the only way to get rid of him. We want everything people have in free countries - want people to live in peace as you do across the Mediterranean where life doesn't require the machinegun."
In Sirte, a one-time fishing village that Gaddafi's grandiose schemes styled a new "capital of Africa" for the "king of kings", fighters whooped with delight and brandished a golden pistol they said they had taken from Gaddafi.
Accounts were hazy of his final hours, as befitted a man who retained an aura of mystery in the desert down the decades as he first tormented "colonial" Western powers by sponsoring militant bomb-makers from the IRA to the PLO and then embraced the likes of Tony Blair and Silvio Berlusconi in return for investment in Libya's extensive oil and gas fields.
There was no shortage of fighters willing to claim they saw Gaddafi, who long vowed to die in battle, cringeing below ground, like Saddam eight years ago, and pleading for his life.
One description, pieced together from various sources, suggests Gaddafi tried to break out of his final redoubt at dawn in a convoy of vehicles after weeks of dogged resistance.
However, he was stopped by a French air strike and captured, possibly some hours later, after gun battles with NTC fighters who found him hiding in a drainage culvert.
NATO said its warplanes fired on a convoy near Sirte about 8:30 a.m. (0630 GMT), striking two military vehicles in the group, but could not confirm that Gaddafi had been a passenger. France later said its jets had halted the convoy, which was comprised of some 80 vehicles.
Libyan television carried video of two drainage pipes, about a metre across, where it said fighters had cornered a man who long inspired both fear and admiration around the world.
After February's uprising in the long discontented east of the country around Benghazi -- inspired by the Arab Spring movements that overthrew the leaders of neighbouring Tunisia and Egypt -- the revolt against Gaddafi ground slowly across the country before a dramatic turn saw Tripoli fall in August.
An announcement of "liberation" -- the signal for the start of a transition to elections -- was expected on Saturday. Libya's newn rulers face the challenge of turning oil wealth once monopolised by Gaddafi and his clan into a democracy that can heal an array of tribal and ethnic divisions he exploited.
The eight weeks since the fall of Tripoli have tested the nerves of the motley alliance of anti-Gaddafi forces and their Western and Arab backers, who had begun to question the ability of the NTC forces to root out diehard Gaddafi loyalists in Sirte and a couple of other towns.
Gaddafi, wanted by the International Criminal Court on charges of ordering the killing of civilians, was toppled by rebel forces on Aug. 23, a week short of the 42nd anniversary of the military coup which brought him to power in 1969.
By averting a possible dispute in Libya and internationally about where to try him, and denying him a final platform for his trademark lengthy speeches, the summary killing on a desert road may have been helpful for Libyans, some analysts said.
Hundreds of NTC troops had surrounded the Mediterranean coastal town of Sirte for weeks in a chaotic struggle that killed and wounded scores of the besieging forces and an unknown number of defenders. One NTC official on Thursday recalled an estimate that some 40,000 have died this year.
"There is now this massive expectation. Up to now they've had an excuse that they are running a war. They don't have that now ... Everything now has got to happen," John Hamilton, a Libya expert at Cross Border Information, told Reuters.
"That's a hard task. They have to deliver for the people ... On the other hand, this may renew the honeymoon they enjoyed when Tripoli fell."
Some fear instability may linger and unsettle that process.
"Gaddafi is now a martyr and thus can become the rallying point for irredentist or tribal violence -- perhaps not in the immediate future but in the medium-to-long term," said George Joffe, a north Africa expert at Cambridge University.
"The fact that NATO can be blamed for his death is worrying, in terms of regional support, and may undermine the legitimacy of the National Transitional Council."
The death of Gaddafi is a setback to campaigners seeking the full truth about the 1988 bombing over Lockerbie in Scotland of Pan Am flight 103 which claimed 270 lives, mainly Americans, and for which one of Gaddafi's agents was convicted.
Jim Swire, the father of one of the Lockerbie victims, said: "There is much still to be resolved and we may now have lost an opportunity for getting nearer the truth." (Additional reporting by Taha Zargoun in Sirte, Barry Malone, Yasmine Saleh and Jessica Donati in Tripoli, Brian Rohan in Benghazi, Jon Hemming in Tunis, Edmund Blair and Yasmine Saleh in Cairo, Samia Nakhoul in Amman, Christian Lowe in Algiers, Tim Castle, Peter Apps and William Maclean in London, David Brunnstrom in Brussels, Alister Bull, Jeff Mason and Laura MacInnis in Washington and Vicky Buffery in Paris; Writing by Alastair Macdonald; Editing by Giles Elgood)