The 1977 Ogaden War, specifically how it was conducted, serves as a clear example of winning every battle but ultimately losing the war.
Siad Barre was incapable of effective politicking and overplayed his hand. The Soviets were initially torn, which was all that was needed, but Barre pushed too hard, demanding that the Soviets completely disavow Ethiopia and accept the annexation of the Ogaden. When the Soviets didn't comply, Barre severed ties with the expectation that they would come crawling back. Instead, he forced the Soviets to make a choice, allowing them to fully back Ethiopia, a country they already had an affinity for. Prior to this, the Soviets were hesitant due to Ethiopia's instability compared to Somalia's relative stability.
Barre was naive to believe that the Americans would immediately provide the same level of sophisticated weaponry, especially in the midst of the war. The fact that the entire Somali army was built on Soviet doctrine and equipment made maintaining the military even more difficult after cutting ties.
In the end, losing the war led to economic hardship and increased public questioning of Barre's leadership. His legitimacy relied heavily on the nationalist fervor he had inspired, which he ultimately failed to deliver on. To maintain power, he increasingly relied on his inner circle, setting the stage for the eventual collapse of his regime.
Barre should have done what the Armenians and Russians did post Soviet Union. Defacto annex it but de jure create an independent government and hold onto it for years. Ethiopia would have even more internal stability and put them in an even worse position during the Eritrean-Ethiopian (civil) war. At that point decades would have past and put Somalia in a better position to balkanize Ethiopia.