Sydney - Papua New Guinea Prime Minister Peter O'Neill was re-elected as leader of the South Pacific island nation on Wednesday, following a complex, chaotic election plagued by violence and allegations of ballot fraud.The nation's Parliament elected O'Neill to a second five-year term by a vote of 60 to 46, after his People's National Congress party won enough seats to form a coalition government with other minor parties.Polling in Papua New Guinea - a rugged, mountainous country that is considered one of the world's most corrupt nations - is a lengthy, complicated process monitored by police and soldiers. Voting began in June, and counting took weeks. Along the way, violent protests broke out over allegations of vote-counting fraud and two police officers were killed. The election's legality has already being challenged in court, and counting was still underway in several electorates even as O'Neill was being sworn in.Still, the 52-year-old prime minister said he was pleased with the way the poll had been conducted, telling Parliament in a speech that it had been the most peaceful election ever held in many parts of the country."We've heard what the people have said in the elections, we've taken stock of it and we will do every bit to do it better," he said.It's true that O'Neill's re-election process was relatively placid compared to the way he initially came to power. In 2011, he replaced Prime Minister Michael Somare while Somare was in Singapore undergoing heart surgery. Both Somare and O'Neill then spent months claiming to be prime minister, setting off a constitutional crisis in which the Supreme Court backed Somare, while a majority of Parliament backed O'Neill.O'Neill eventually won a mandate in a 2012 election, vowing to combat corruption in a country that ranked 136th among 176 nations last year in Transparency International's Corruption Perception Index.But O'Neill's attempts to clean up corruption in the country didn't go particularly well. He disbanded his anti-corruption task force after it tried to execute an arrest warrant on him over allegations of fraud involving government payments made to a private law firm. The Supreme Court ordered that his arrest warrant not be executed, but many members of the public believed that O'Neill had placed himself above the law.On Wednesday, O'Neill acknowledged in his speech to Parliament that no government is perfect, and vowed to make improvements.The prime minister managed to stave off a challenge from opposition leader Don Polye, a 50-year-old former minister in O'Neill's government and leader of the Triumph Heritage Empowerment Party. Polye campaigned against what he dubbed the government's economic mismanagement through burgeoning debt.Papua New Guinea's largest export is liquefied natural gas. The ExxonMobil-operated PNG LNG project began exporting to Japan in 2014, but many Papua New Guineans have asked where the revenue has gone.Stephen Howes, a professor at Australian National University and a Papua New Guinea expert, said O'Neill's immediate challenge will be addressing the country's economic woes. He will also continue to face controversy. The election has already been challenged by an opposing candidate, who asked the Supreme Court to decide whether holding the vote on a Sunday breached the country's constitution."I think he has a mandate, but the allegations of corruption won't go away," Howes said. "He'll continue to be dogged by controversy."