Gunfire echoed through the slums of Nairobi on Friday night after President Uhuru Kenyatta was declared the winner of a disputed election, triggering a violent outpouring of anger in opposition strongholds.

Screams and gunshots could be heard in several of the capital’s poorer districts moments after the electoral commission sought to end a four-day impasse over the outcome of Tuesday’s vote by announcing Mr Kenyatta’s sweeping victory over his rival Raila Odinga.

The president secured a second five-year term after winning 54 per cent of the vote, a 1.4 million vote margin that was larger than opinion polls suggested. The opposition rejected the result even before it was announced, complaining of "systematic" fraud.

With violent protests also being reported in Kisumu, Kenya’s third city, there were fears that the former British colony could witness a reprise of the violence that claimed 1,300 lives after Mr Odinga’s defeat in another election ten years ago.

Members of Mr Odinga’s Luo ethnic group attacked property belonging to members of the president’s tribe in Nairobi’s Kibera slum as police struggled to control the violence, despite being deployed in record numbers.

“They are burning down Kikuyu homes,” a resident said.

With 180,000 security personnel drawn from the army, police and even the forestry service on standby, Kenyan authorities will hope to stamp out the violence quickly.