Ali denied raping 28-year-old Fadumo Hasan Mohmoud.
Somalia's militant Islamist group al-Shabab implements a strict version of Islamic law in areas it controls.
Last month, a woman was stoned to death in the port town of Barawe after an Islamic court convicted her of having four husbands at the same time.
Ali was found guilty of raping Ms Mohmoud at gunpoint in Dharuro village in Somalia's Lower Shabelle region, reports the pro-al-Shabab al-Furqaan radio station on its website.
He said he had consensual sex with her.
Al-Shabab has recently lost control of several towns, including Barawe, but still controls large swathes of territory in rural areas.
The al-Qaeda linked group, which is estimated to have at least 5,000 fighters, wants to overthrow the UN-backed Somali government. .