"What seems to matter is the ethnicity of the candidates - one reason why Kenyans keep voting for the wrong people." Editorial, The Daily Nation.

When will Kenya get the leaders it deserves? I fell in love with the country at first sight 23 years ago: chilly dawns in the Masai Mara, where you can take in a thousand grazing animals in a single panorama; walks along a seemingly endless white beach beside the Indian Ocean, fringed with palms and a pair of ospreys for company; the resourcefulness and ebullience of the people. Were it not for Kenya's venal politics and appalling infrastructure, by now it would surely be the African lion to match the tiger economies of the Far East.

In the intervening decades, I've watched Kenya creep forward but more despite its governments than because of them. Three months ago I returned from our friends' wedding in Tsavo with a real sense of hope. The rains have been good this year and, in place of the usual dry bushes and ubiquitous red dust, everywhere was abundant growth. The economy, too, seemed to be greening. Vehicle numbers in Nairobi have doubled in a couple of years, generating unprecedented congestion and every gap site seems to have sprouted scaffolding in a frenzy of construction work. In the countryside each boy appeared to have acquired a bicycle and even in the remotest village someone was flourishing a mobile phone. The last phase of the Nairobi to Mombasa highway is under construction. In 20 years, Nairobi has been transformed from a hick Wild West-style place to a steel and glass city housing a host of African HQ buildings for global businesses and NGOs. And tourism was finally taking off. Our family were once the sole visitors to one national park. Now tourist minibuses were rattling by every few minutes.

Everywhere I met bright ambitious young people. People such as Kip, a handsome Masai warrior who proudly showed us a modern tourist lodge overlooking a spectacular escarpment near Mount Kenya and explained the microcredit scheme that enabled his community to build it. People such as Ireen, one of the four girls I pay through secondary school, who is third in her class of 112 and still writes saying she will "try to improve".

Nevertheless, Kenya is still massively hampered by corruption. A glance at almost any edition of The Daily Nation shows what a pre-occupation it has become. Kenyans are fed up with police enriching themselves by pocketing motorists' fines or new road surfaces that break-up because half the tarmac was flogged off the back of a lorry. In post-colonial Africa, corruption and graft are so ingrained that backhanders can add 25% to the cost of an infrastructure project. Despite this, Kenya has sustained 5% annual economic growth since 2002 and, against the odds, there is now free universal primary education.

So why have allegations of vote-rigging in last week's elections provoked such anger and bloodshed? The death toll surpassed 300 yesterday, including a number of women and children trapped in a burning church in the town of Eldoret. As two-thirds of the Kenyan population are under 40, this is the worst violence most of them have witnessed. Ever since multi-party politics was reintroduced in 1991 there has been an element of rigging in every election but it has probably never been big enough to throw the result.

It's the scale and blatancy of cheating this time around that has unleashed such murderous fury. In one government-held constituency, there was a reported 115% turnout. Overall, the opposition Orange Democratic Movement (named after the revolution in Ukraine) calculated that at least 750,000 votes were stolen from it. This would have given its candidate, Raila Odinga, a 500,000 margin of victory, instead of the 200,000 majority claimed by the Kibaki camp.

The irony is that Mwai Kibaki was swept to power in 2002 on a one-nation, anti-corruption platform but then proceeded to suppress inquiries into corruption and appoint his cronies to all the key posts. This so-called "Mount Kenya Mafia" were overwhelmingly from the dominant Kikuyu, who make up 22% of the population. Kikuyu areas continue to receive the lion's share of investment. John Githongo, the former journalist he appointed as anti- corruption czar, was forced to flee to Britain after threats on his life.

Odinga is from the Luos, who make up around 14%, the second largest of Kenya's 42 ethnic groups. A former supporter of Kibaki, he resigned in disgust when the President broke a promise to make him Prime Minister in 2002. After a break with tribalism that year and while some disillusioned Kikuyu withheld support from their President this time, most Kenyans seem to have reverted to voting along traditionally ethnic and tribal lines.

Some of those interviewed this week assert that poverty, not tribalism and corruption, was the major issue. But surely they are different sides of the same coin. Despite recent advances, more than half of Kenyans try to survive on less than $1 a day. Corruption is a mechanism for redistributing to one's own group what money there is in a society where too many people are fighting for a share of too small a cake. Or as Kenyan politicians put it: "It is our turn to eat."

Would Odinga be any different? He, too, is from one of Kenya's dynastic political families. His father was the country's first post-independence Vice-President. His opponents accuse him of megalomania and he has even been compared with Uganda's crazed and brutal ex-dictator, Idi Amin.

Today Kenya is a country going backwards. With little electricity or fuel, no live radio or television and (significantly) nowhere to buy mobile phone top-ups, its people are cut off and prey to rumour and propaganda. It is in these conditions that a few hundred tit-for-tat killings could flare into bloody civil war.

Amazingly, there is some hope. Kibaki's troops seem reluctant to fire on their own people on the say-so of a President of such dubious legitimacy. Today's ODM rally will be a test of that. In the longer term, the old hippos of Kenyan politics are gradually disappearing. No fewer than 12 cabinet ministers lost their seats, including those at the centre of corruption allegations. Kibaki can now count on barely 30 of his own party in the new parliament.

Meanwhile, a group of young cheetahs, who style themselves Kizazi Kipya (new generation), who fund their campaigns through websites and reject hidebound party politics, were standing for the first time. Born after independence and well-educated, they are prepared to put country above tribe or ethnicity. Amid the confusion, I was unable to discover yesterday how many of them were elected but I believe that eventually these energetic young leaders will come through.

Kenya stands on a knife-edge. Barely three months ago my family stood on the banks of Kenya's Athi River under a huge African moon and watched our newly-wed friends embark, slightly awkwardly, on their first waltz beside their crazy, beautiful, handmade, sticks-and-stones house. Someone had painted the words "Dreams Come True" on the improvised concrete dancefloor and, at that moment, it felt like a metaphor for the whole of their crazy, beautiful country. After years of confusion and disappointment, Kenya seemed on the brink of becoming a modern democratic state that would deliver decency and dignity to all its people and become the role model for a troubled continent. Today that dream looks painfully fragile.