Gunmen in a moving car opened fire as the lawmaker drove through the centre of the city, before racing off, witnesses said. MP Mustafa Mayow was wounded in the attack.
"The government say they have eradicated the al-Shabaab from Mogadishu, but this is to show that we are here and active," al-Shabaab spokesperson Abdiaziz Abu Musab told AFP.
The al-Qaeda-affiliated al-Shabaab rebels are fighting to overthrow the country's internationally-backed government.
At least five lawmakers have been killed in Mogadishu this year. The extremists say they are targeting MPs as they allowed the deployment of foreign troops on Somali soil.
Recent al-Shabaab attacks in Somalia have targeted key government and security sites in an apparent bid to discredit claims by the authorities and African Union troops that they are winning the war.
On Wednesday an al-Shabaab suicide bomber killed four security guards and bystanders when they rammed a car packed with explosives into a United Nations convoy.
The al-Shabaab have also stepped up operations in neighbouring Kenya, and on Tuesday massacred 36 non-Muslim quarry workers in a Kenyan border town.