This is a tale of two neighbours: one on the brink of national disaster, unless mediation can prevent a new wave of ethnic killing; the other already in full-scale collapse, with no functioning government or basic services, and 700,000 people driven from their homes. The first is being watched attentively by foreign governments; the second has dropped off the radar, abandoned by those same governments because it all seems so difficult.

I refer to Kenya and Somalia, countries that illustrate the inconsistencies in international policy-making David Miliband failed to reflect in his speech on interventionism this week. Long-standing economic injustices, grievances over land and water, ethnic and clan discrimination, and chronic under-development cannot be corrected by sudden surges of interest and moral fervour. They need decades of subtle care and unflagging attention.

Kenya's case is the more hopeful. Kofi Annan, the former UN secretary general, and a team of UN advisers have been talking to both sides in a secluded safari lodge to find a power-sharing formula after December's flawed presidential election. This is intelligent intervention, impartial and headline-avoiding. Foreign governments are taking a back seat. The US initially favoured President Mwai Kibaki on the false grounds that the Kikuyu have always been the best motor for Kenya's progress. It also disliked the fact that Raila Odinga, the opposition leader, condemned the way suspects in the "war on terror" were subject to "extraordinary rendition". But now Washington is standing aside, Britain too is lying low, wary of the charge of neocolonial interference.

Whether Annan can get agreement when the talks resume next week remains to be seen. Though the evidence points to Odinga winning the election - his party won two-thirds of the seats in the simultaneous and less riggable parliamentary elections - his side has made the larger concessions. It has dropped its insistence on Kibaki standing down, and its demands for an early re-run of the stolen election, and is considering the Annan proposal for a two-year pause. It has hinted at readiness to split the ministries in a coalition cabinet 50-50.

A deal on these lines will be tough for Odinga to sell, especially as Kibaki reneged on a 2002 deal to reduce the power of the presidency and create a prime minister. "Kibaki's problem is with his elite, Odinga's is with his base," as one observer put it this week. Any agreement Annan comes up with must be anchored in law and some form of continuing UN supervision. The anti-Kikuyu anger and killings that swept through parts of the Rift Valley last month could explode again if people feel Odinga has given up too much. So another part of the deal should be a carefully monitored role for the Kenyan army to forestall rioting - a necessary but risky proposition, since the army is poorly trained for crowd control.

If Kenya's eruption into violence shocked the world by being unexpected, Somalia's collapse was fully foreseen. As many experts warned, US collusion with Ethiopia a year ago to send Ethiopian troops into Mogadishu to topple the Islamic Courts regime has backfired as badly as the invasion of Iraq. According to reports from UN and other aid workers in Somalia, almost three-quarters of a million people have fled since the Ethiopians arrived. Far from eliminating the Islamic Courts, the invasion attracted waves of new recruits, motivated by resentment at the presence of foreign troops and not just by jihadi ideology. The Ethiopians installed one of the worst Somali warlords as mayor of Mogadishu, allowing him to turn his militia into the police. Most of the capital's people are from a different clan.

Resistance has intensified in the past months as the occupation shows no sign of ending, and Islamist insurgents now operate well beyond Mogadishu. Indiscriminate mortaring and machine-gun fire by all sides is said by aid workers to be horrendous, though there are no TV cameras to raise international alarm. Adding to the chaos, insurgent groups are splitting - with the same erosion of discipline and clan rivalry that have divided rebel movements in Darfur. This reduces the chance of holding successful peace talks. Banditry is on the rise with aid workers increasingly targets, as last month's killing of three staff for Médecins sans Frontières demonstrates. MSF has now withdrawn all its international doctors, leaving hospitals without surgeons.

Meanwhile, Somalia's Transitional Federal Government (TFG) still sits in the town of Baidoa, with no presence in the capital except for a fortified and symbolic mini-green zone. What little support the TFG had in Mogadishu has disappeared. In November, fighting prompted another 200,000 people to escape into the desert, meaning that more than half the capital's population has left. In a grim reversal of urbanisation, they know it is safer to live outside Mogadishu. Only the poorest and weakest remain inside the ruined city.

Here is a catastrophe crying out for sustained and well-funded UN intervention. It would not be a case of overthrowing a government, since there is none. It is not an issue of using "soft power" or sanctions against a bad regime. It is a blatant example of a massive humanitarian emergency, to which the so-called international community is content to turn a blind eye. The TFG was cobbled together by foreign governments, knowing its legitimacy was thin. They tolerated the Ethiopian invasion because Washington wanted it. Now these governments stumble on, bereft of ideas, privately glad that the media do not highlight the issue so their inaction can continue.

Under an African Union mandate, Uganda and Burundi have sent a few hundred troops (their airlift paid in part by Britain), but Rwanda pulled out and Nigeria stalled. Now Ban Ki-moon, the UN secretary general, has sent a mission to assess if a more powerful UN force can replace the discredited invaders. But will the big powers back him in urgently alleviating the present misery? Will they recognise their earlier mistake and find a political compromise? Demonising all the Islamists as terror-mongers makes no sense and will not bring peace. Talks between the TFG and the Islamists are the only way out. In Kenya, there is at least mediation and a chance of compromise. In Somalia, there is nothing on offer because the security council got it wrong and has all but given up.