After gaining independence in 1963 and throughout the Cold War, Kenya tried to stay away from the internal and external struggles of its neighbourhood. While Ethiopia allied itself with the erstwhile USSR and Cuba, Somalia aligned with the United States and Tanzania became the intellectual hotbed for the Third World left, Kenya maintained poised neutrality and a policy of non-intervention.

Daniel Moi, the country's second president after independence, sought to firewall Kenya from spillovers of regional conflict by maintaining a foreign policy of ideological ambivalence - being neither a friend nor a foe of regional and international powers.

Moi also took up mediating conflicts in the region and made it the main feature of Kenyan diplomacy which carried on even after the end of the Cold War. During his presidency, Kenya became the venue for peace negotiations between the warring sides in Sudan, Somalia, and Uganda.

Various agreements were negotiated and concluded in Nairobi, including the 1985 peace deal between the Ugandan government of Tito Okello and the National Resistance Army (NRA), a rebel group led by Yoweri Museveni and the 2005 peace agreement between the Sudanese government and southern rebels, which ended Africa's longest-running civil war.

Kenya also played an important mediation role in the Somali conflict, hosting the negotiations and the signing of the agreement that led to the creation of the Transitional Federal Government (TFG) in 2004.

This strategy not only ensured Kenya's internal affairs were undisturbed by regional developments but also earned it a certain diplomatic reputation in the region.

Today, both of these are on the line because of repeated mistakes Kenya is making in its policies towards Somalia. Kenyan military presence on Somali land has entered its ninth year, which has now metastasised into entanglement in Somalia's internal affairs and encouraged more al-Shabab violence on Kenyan territory. Kenya's imprudent stance on its maritime dispute with Somalia also threatens to erode its international reputation.

From intervention to occupation

For decades, bilateral relations between Kenya and Somalia remained warm and cordial. But in 2011, the Kenyan government decided to send troops to its neighbour, which since then has been a source of considerable friction between Nairobi and Mogadishu.

Kenya's intervention in Somalia was in line with the zeitgeist of the "war on terror" launched by the US in 2001. Packaging the intervention as an "anti-terror" operation automatically guaranteed domestic support and international immunity for human rights violations.

The official justification for the military intervention was the pursuit of al-Shabab members who allegedly abducted aid workers in northern Kenya and kidnapped tourists along the coast.

The intervention has since degenerated into an occupation. Currently, there are more than 3,600 Kenyan troops in Somalia, primarily deployed in the semi-autonomous southern Somali region of Jubaland.

Over the past eight years, the Kenyan forces have been accused of committing various human rights violations against civilians and being involved in illicit smuggling activities. The Somali government has demanded that Kenyan troops leave, but it has not followed up with any serious effort to expel them, given its own limited capacity to provide security.

At the same time, the Kenyan military presence has done little to secure Kenya from al-Shabab's attacks or Somalia itself for that matter. In fact, violence has escalated since the intervention.

Kenya has witnessed a number of large-scale al-Shabab operations, like the ones in Westgate Mall in 2013, and the Garissa University in 2015, which took the lives of hundreds of civilians, as well as numerous low-grade and low casualty ones.

Since October, there have been on average two al-Shabab attacks every week in Kenya and Somalia. In the first half of this month alone, the armed group raided a military camp used by Kenyan and US soldiers in southern Kenya and then launched four other attacks, killing 10 civilians.

The intervention has revealed the underbelly of Kenya's security policy, its failed military strategy and the inability to police its own borders.

Support for Jubaland

Alongside the military intervention, Kenya has also involved itself in the maelstrom of Somali domestic politics.

Its principal vehicle of involvement in Somalia is Sheikh Ahmed Mohamed Islam, also known as Madobe, an Islamist militia commander from the Somali Ogaden clan.

Madobe is seen as a rather controversial figure, having switched sides in Somalia's civil war multiple times. He was part of various Islamist armed groups since the 1990s. He has fought against the government in Mogadishu as an ally of al-Shabab for years and was involved with militants seen as supportive of the Ogaden National Liberation Front (ONLF), a separatist group who has fought for Somali self-determination in eastern Ethiopia.

In 2007, a year after Ethiopia sent troops to Somalia to back the TFG against the Islamist insurgency, Madobe was hit by a US bombing and captured by the Ethiopians, who offered him a political deal. He accepted to join the TFG in 2009, but shortly after he deserted his new post and with his Ras Kamboni militia joined al-Shabab in their fight against government and African Union troops.

In 2011, he struck another deal, this time with Nairobi, and the following year, his militia, backed by Kenyan troops, managed to expel al-Shabab from Jubaland's capital, Kismayo, which is also a strategic port city.

Over the next two years, Madobe presided over clan reconciliation and in 2015, with Kenyan backing, he was elected president of Jubaland. In the 2019 presidential election in the semi-autonomous state, Nairobi again supported his candidacy, despite the fact that the Somali government opposed it.

Kenya's backing for Madobe has revealed that all along it was not only interested in containing al-Shabab, but in establishing a "sphere of influence" through Jubaland - a satellite statelet, remote-controlled from Nairobi.

This misguided support for Jubaland, however, is something anyone with a basic understanding of the dynamic in the Horn of Africa would have counselled against. For the fragile government in Mogadishu, the strengthening of Jubaland means the weakening of its powers.

For Ethiopia, Kenya's interference in a region predominantly populated by the Ogadens, the largest Somali clan, whose members also live in southern Ethiopia and have a fraught with the government, is creating unnecessary tension.

Thus, Kenya is not only endangering its relationship with the Somali government but also with Ethiopia, a neighbour and a major regional power, with whom it has a decades-old defence pact to ensure regional stability and curb Somali irredentism.

The maritime dispute

If Kenya's original sin was the 2011 intervention, its natural outcome is the needless maritime dispute with Somalia. Both Nairobi and Mogadishu claim a narrow triangle of about 100,000 square kilometres off their coasts in the Indian Ocean. The territory supposedly has oil and gas deposits.

The dispute could have been resolved amicably had Kenyan officials taken the issue seriously and had they regarded their Somali counterparts with some modicum of respect rather than assuming Somalia is a failed state incapable of mounting any defence.

As a result, the case eventually ended up at the International Court of Justice (ICJ), which last year decided to delay its ruling to 2020 to let the two sides negotiate further.

Instead of correcting their earlier mistakes, Kenya's ministry of foreign affairs officers dug in their heels and started engaging in petty moves like denying Somali officials entry into the country and reintroducing flight stopovers in Wajir for security checks for all flights to and from Somalia, substituting petulance for diplomacy.

For decades, Somalia has regarded Kenya as a neutral arbiter compared with Ethiopia which Somalis have resented for its multiple military interventions. The overarching danger is that, in the end, Kenya's intervention and meddling in Somalia's internal affairs, coupled with the self-aggrandisement of a bubbling and venal elite, could ruin Kenyan-Somali relations.

This will also undermine the authority and capacity of the federal Somalia government to administer the country, especially if AMISOM troops depart as scheduled by December 2020.

The net winner of these squabbling and reckless diplomacy will be al-Shabab, which will continue to enjoy enough space to launch attacks in Kenya and within Somalia. The ultimate loser will be the Somali people who have endured decades of conflict.

The views expressed in this article are the author's own and do not necessarily reflect Al Jazeera's editorial stance.