Ali was involved in the 1971 Ugandan coup d'état that overthrew President Milton Obote and brought Idi Amin to power. He consequently rose in the ranks during the duration of the Second Republic of Uganda, when Amin ruled the country as military dictator. Ali was appointed Minister of Finance, and used his position to organize an Islamic charity. This garnered him a lot of popular support, but also raised Amin's suspicions, as he feared Ali was attempting to construct a Muslim political base of support. In April 1978, the President organized a meeting in the capital Kampala, where he railed against ministers whom he deemed disloyal, too powerful or incompetent, including Ali. Accusing the Minister of Finance of mismanaging the Bank of Uganda and gross corruption, Amin became so angry during his speech that he threw a trashcan at Ali. Having realized that his situation was untenable, Ali get away as soon as possible. He quietly snuck out of Kampala in his private car and fled to his home in the West Nile region. When got there, however, a group of hitmen attacked him, but he fended them off in a gunfight. Ali was convinced that his downfall and the attempted assassination had been organized by the Uganda Army commander Yusuf Gowon, a long-time rival of his. Amin subsequently stripped him of all of his military honours. When Amin's regime collapsed during the Uganda–Tanzania War of 1978—1979, Ali fled into exile in southern Sudan, finding refuge in Nimule. In the 1980s he led the Uganda National Rescue Front in an armed rebellion against the government of reinstated President Milton Obote, and became a warlord ruling a fief in southern Sudan. Using his influence and military poweress to his advantage, Ali eventually negotiated a favorable deal with Yoweri Museveni who took power as President at the Ugandan Bush War's end in 1986. His forces were integrated into Uganda's new national army, the National Resistance Army which later became the Uganda People's Defence Force, and he was appointed a general. As a result of his powerful position in Uganda's new government and military, Ali became highly influential and quite wealthy. Ali even rose to First Deputy Prime Minister in Museveni's government. He served in the Ugandan Parliament from 2001. He was further promoted to lieutenant general on 13 March 2003, but lost both his parliamentary seat and his ministerial appointment in 2006. In 2011, at the age of 72, he regained his position in parliament and was assigned new cabinet responsibilities. In the next year, Ali was once again promoted to four-star general in the UPDF. In 2016, following his re-election to parliament, he was again appointed First Deputy Prime Minister and Deputy Leader of Government Business in Parliament.