Following World War II, Britain retained control of both British Somaliland and Italian Somaliland as protectorates. In 1950, as a result of the Paris Peace Treaties, the United Nations granted Italy trusteeship of Italian Somaliland, but only under close supervision and on the condition—first proposed by the Somali Youth League (SYL) and other nascent Somali political organizations, such as Hizbia Digil Mirifle Somali (HDMS) and the Somali National League (SNL)—that Somalia achieve independence within ten years. British Somaliland remained a protectorate of Britain until 1960.
In 1948, under pressure from their World War II allies and to the dismay of the Somalis, the British returned the Haud (an important Somali grazing area that was presumably 'protected' by British treaties with the Somalis in 1884 and 1886) and the Ogaden to Ethiopia, based on a treaty they signed in 1897 in which the British, French and Italians agreed upon the territorial boundaries of Ethiopia with the Ethiopian Emperor Menelik in exchange for his help against raids by hostile clans. Britain included the provision that the Somali residents would retain their autonomy, but Ethiopia immediately claimed sovereignty over the area. This prompted an unsuccessful bid by Britain in 1956 to buy back the Somali lands it had turned over. Britain also granted administration of the almost exclusively Somali-inhabited Northern Frontier District (NFD) to Kenyan nationalists despite an informal plebiscite demonstrating the overwhelming desire of the region's population to join the newly formed Somali Republic.
A referendum was held in neighboring Djibouti (then known as French Somaliland) in 1958, on the eve of Somalia's independence in 1960, to decide whether or not to join the Somali Republic or to remain with France. The referendum turned out in favour of a continued association with France, largely due to a combined yes vote by the sizable Afar ethnic group and resident Europeans. There was also widespread vote rigging, with the French expelling thousands of Somalis before the referendum reached the polls. The majority of those who voted no were Somalis who were strongly in favour of joining a united Somalia, as had been proposed by Mahmoud Harbi, Vice President of the Government Council. Harbi was killed in a plane crash two years later. Djibouti finally gained its independence from France in 1977, and Hassan Gouled Aptidon, who had campaigned for a yes vote in the referendum of 1958, eventually wound up as Djibouti's first president (1977–1991).
British Somaliland became independent on 26 June 1960 as the State of Somaliland, and the Trust Territory of Somalia (the former Italian Somaliland) followed suit five days later. On July 1, 1960, the two territories united to form the Somali Republic. A government was formed by Abdullahi Issa and other members of the trusteeship and protectorate governments, with Haji Bashir Ismail Yusuf as President of the Somali National Assembly, Aden Abdullah Osman Daar as President of the Somali Republic and Abdirashid Ali Shermarke as Prime Minister (later to become President from 1967–1969). On 20 July 1961 and through a popular referendum, the people of Somalia ratified a new constitution, which was first drafted in 1960.
On 15 October 1969, while paying a visit to the northern town of Las Anod, Somalia's then President Shermarke was shot dead by one of his own bodyguards. His assassination was quickly followed by a military coup d'état on 21 October 1969 (the day after his funeral), in which the Somali Army seized power without encountering armed opposition — essentially a bloodless takeover. The putsch was spearheaded by Major General Mohamed Siad Barre, who at the time commanded the army.
Alongside Barre, the Supreme Revolutionary Council (SRC) that assumed power after President Sharmarke's assassination was led by Lieutenant Colonel Salaad Gabeyre Kediye and Chief of Police Jama Korshel. Kediye officially held the title of "Father of the Revolution," and Barre shortly afterwards became the head of the SRC. The SRC subsequently renamed the country the Somali Democratic Republic, dissolved the parliament and the Supreme Court, and suspended the constitution.
In addition to previous Soviet funding and arms support to Somalia, Egypt sent millions of dollars in arms to Somalia, established military training and sent experts to Somalia in support of Egypt's longstanding policy of securing the Nile River flow by destabilising Ethiopia.
As Somalia gained military strength, Ethiopia grew weaker. In September 1974, Emperor Haile Selassie had been overthrown by the Derg (the military council), marking a period of turmoil. The Derg quickly fell into internal conflict to determine who would have primacy. Meanwhile, various anti-Derg as well as separatist movements began throughout the country. The regional balance of power now favoured Somalia.
One of the separatist groups seeking to take advantage of the chaos was the pro-Somalia Western Somali Liberation Front (WSLF) operating in the Somali-inhabited Ogaden area, which by late 1975 had struck numerous government outposts. From 1976 to 1977, Somalia supplied arms and other aid to the WSLF.
A sign that order had been restored among the Derg was the announcement of Mengistu Haile Mariam as head of state on February 11, 1977. However, the country remained in chaos as the military attempted to suppress its civilian opponents in a period known as the Red Terror (or Qey Shibir in Amharic). Despite the violence, the Soviet Union, which had been closely observing developments, came to believe that Ethiopia was developing into a genuine Marxist–Leninist state and that it was in Soviet interests to aid the new regime. They thus secretly approached Mengistu with offers of aid that he accepted. Ethiopia closed the U.S. military mission and the communications centre in April 1977.
In June 1977, Mengistu accused Somalia of infiltrating SNA soldiers into the Somali area to fight alongside the WSLF. Despite considerable evidence to the contrary, Barre strongly denied this, saying SNA "volunteers" were being allowed to help the WSLF.
The Somali National Army committed to invade the Ogaden at 03:00 on July 13, 1977 (5 Hamle, 1969), according to Ethiopian documents (some other sources state 23 July). According to Ethiopian sources, the invaders numbered 70,000 troops, 40 fighter planes, 250 tanks, 350 armoured personnel carriers, and 600 artillery, which would have meant practically the whole Somali Army. By the end of the month 60% of the Ogaden had been taken by the SNA-WSLF force, including Gode, on the Shabelle River. The attacking forces did suffer some early setbacks; Ethiopian defenders at Dire Dawa and Jijiga inflicted heavy casualties on assaulting forces. The Ethiopian Air Force (EAF) also began to establish air superiority using its Northrop F-5s, despite being initially outnumbered by Somali MiG-21s. However, Somalia was easily overpowering Ethiopian military hardware and technology capability. Army-general Vasily Petrov of the Soviet Armed Forces had to report back to Moscow the "sorry state" of the Ethiopian Army. The 3rd and 4th Ethiopian Infantry Divisions that suffered the brunt of the Somali invasion had practically ceased to exist.
The USSR, finding itself supplying both sides of a war, attempted to mediate a ceasefire. When their efforts failed, the Soviets abandoned Somalia. All aid to Siad Barre's regime was halted, while arms shipments to Ethiopia were increased. Soviet military aid (second in magnitude only to the October 1973 gigantic resupplying of Syrian forces during the Yom Kippur War) and advisors flooded into the country along with around 15,000 Cuban combat troops. Other communist countries offered assistance: the People's Democratic Republic of Yemen offered military assistance and North Korea helped train a "People's Militia"; East Germany likewise offered training, engineering and support troops. (As the scale of communist assistance became clear in November 1977, Somalia broke diplomatic relations with the USSR and expelled all Soviet citizens from the country.)
Not all communist states sided with Ethiopia. Because of the Sino-Soviet rivalry, China supported Somalia diplomatically and with token military aid. Romania under Nicolae Ceauşescu had a habit of breaking with Soviet policies and maintained good diplomatic relations with Siad Barre.
By 17 August elements of the Somali army had reached the outskirts of the strategic city of Dire Dawa. Not only was the country's second largest military airbase located here, as well as Ethiopia's crossroads into the Ogaden, but Ethiopia's rail lifeline to the Red Sea ran through this city, and if the Somalis held Dire Dawa, Ethiopia would be unable to export its crops or bring in equipment needed to continue the fight. Gebre Tareke estimates the Somalis advanced with two motorized brigades, one tank battalion and one BM battery upon the city; against them were the Ethiopian Second Militia Division, the 201 Nebelbal battalion, 781 battalion of the 78th Brigade, the 4th Mechanized Company, and a tank platoon possessing two tanks. The fighting was vicious as both sides knew what the stakes were, but after two days, despite that the Somalis had gained possession of the airport at one point, the Ethiopians had repulsed the assault, forcing the Somalis to withdraw. Henceforth, Dire Dawa was never at risk of attack.
The greatest single victory of the SNA-WSLF was a second assault on Jijiga in mid-September (the Battle of Jijiga), in which the demoralized Ethiopian troops withdrew from the town. The local defenders were no match for the assaulting Somalis and the Ethiopian military was forced to withdraw past the strategic strongpoint of the Marda Pass, halfway between Jijiga and Harar. By September Ethiopia was forced to admit that it controlled only about 10% of the Ogaden and that the Ethiopian defenders had been pushed back into the non-Somali areas of Harerge, Bale, and Sidamo. However, the Somalis were unable to press their advantage because of the high attrition on its tank battalions, constant Ethiopian air attacks on their supply lines, and the onset of the rainy season which made the dirt roads unusable. During that time, the Ethiopian government managed to raise and train a giant militia force 100,000 strong and integrated it into the regular fighting force. Also, since the Ethiopian army was a client of U.S weapons, hasty acclimatization to the new Warsaw Pact bloc weaponry took place.
From October 1977 until January 1978, the SNA-WSLF forces attempted to capture Harar during the Battle of Harar, where 40,000 Ethiopians had regrouped and re-armed with Soviet-supplied artillery and armor; backed by 1500 Soviet "advisors" and 11,000 Cuban soldiers, they engaged the attackers in vicious fighting. Though the Somali forces reached the city outskirts by November, they were too exhausted to take the city and eventually had to withdraw to await the Ethiopian counterattack.
The expected Ethiopian-Cuban attack occurred in early February; however, it was accompanied by a second attack that the Somalis did not expect. A column of Ethiopian and Cuban troops crossed northeast into the highlands between Jijiga and the border with Somalia, bypassing the SNA-WSLF force defending the Marda Pass. Mil Mi-6 helicopters airlifted Cuban BMD-1 and ASU-57 armored vehicles behind enemy lines. The attackers were thus able to assault from two directions in a "pincer" action, allowing the re-capture of Jijiga in days while killing 3,000 defenders. The Somali defense collapsed and every major Somali towns were recaptured in the following weeks. Recognizing that his position was untenable, Siad Barre ordered the SNA to retreat back into Somalia on 9 March 1978, although Rene LaFort claims that the Somalis, having foreseen the inevitable, had already withdrawn their heavy weapons. The last significant Somali unit left Ethiopia on 15 March 1978, marking the end of the war.
Following the withdrawal of the SNA, the WSLF continued their insurgency. By May 1980, the rebels, with the assistance of a small number of SNA soldiers who continued to help the guerrilla war, controlled a substantial region of the Ogaden. However, by 1981 the insurgents were reduced to sporadic hit-and-run attacks and were finally defeated.
For the Barre regime, the invasion was perhaps the greatest strategic blunder since independence, and it weakened the military. Almost one-third of the regular SNA soldiers, three-eighths of the armored units and half of the Somali Air Force (SAF) were lost. The weakness of the Barre administration led it to effectively abandon the dream of a unified Greater Somalia. The failure of the war aggravated discontent with the Barre regime; the first organized opposition group, the Somali Salvation Democratic Front (SSDF), was formed by army officers in 1979.
The United States adopted Somalia as a Cold War ally from the late 1970s to 1988 in exchange for use of Somali bases, and a way to exert influence upon the region. A second armed clash in 1988 was resolved when the two countries agreed to withdraw their militaries from the border.