Fighting broke out between the extremists and African Union peacekeepers (AMISOM) just outside the capital on Tuesday evening.
Mortar fire hit several neighbourhoods of Mogadishu and fighting broke out between the extremists and African Union peacekeepers (AMISOM) just outside the capital on Tuesday evening, according to police and witnesses.
Such shelling is not unusual in Mogadishu and is a common tactic by Al-Qaeda-linked Shabaab militants seeking to make their presence known. No casualties were reported.
However, fears of further violence were palpable, with Mogadishu on lockdown as MPs headed to the site of the election at the airport, situated within a secure compound which is home to diplomats, aid workers and soldiers.
Hundreds of lawmakers, observers and journalists mixed together in a snaking line for manual security checks to gain access to the hangar where the vote will take place later Wednesday.
Somalia's election has been billed as its most democratic in nearly five decades, even though only 14,000 delegates were able to vote for MPs in a drawn out process marred by delays and accusations of vote-buying and corruption.
The government is only the second to be chosen inside Somalia since the 1991 overthrow of Siad Barre's military regime led to decades of anarchy, however it will still have only limited control of the country.
Despite being ousted from Mogadishu by AMISOM troops in 2011, the Shabaab still launches regular, deadly attacks and holds swathes of countryside. It has also launched devastating strikes on neighbouring Kenya.
Two weeks ago, a twin car bomb attack on a popular Mogadishu hotel left 28 dead while scores of Kenyan soldiers are believed to have died in an attack on a military base in southern Somalia.
Four years after lawmakers were handpicked by 135 clan elders, and then voted for a president, Somalia had been promised a one-person, one-vote election in 2016.
However political infighting and insecurity saw the plan ditched for a limited vote running six months behind schedule.
Repeated delays meant the new lawmakers were only sworn in in December.
In Wednesday's vote, President Hassan Sheikh Mohamud is seeking re-election against 20 other candidates, after several withdrew from the race at the last minute.
The candidates -- all men after the only declared female candidates dropped out -- paid a $30,000 (28,000-euro) registration fee but few have any serious chance of winning.
In the absence of political parties, clan remains the organising principle of Somali politics.
Mohamud, a 61-year-old former academic and civil society activist from the Hawiye clan, is seen as a frontrunner as is ex-president Sharif Sheikh Ahmed, 52, a fellow Hawiye.
The leading candidates from the Darod clan are Prime Minister Omar Abdirashid Ali Sharmarke, 56, and former premier Mohamed Abdullahi Mohamed 'Farmajo', 55.
Both hold dual nationalities having lived for years in Canada and the US respectively.
Mogadishu has been on lockdown since Tuesday ahead of the vote, with main roads blocked off by big mounds of sand, and only heavily-armed security personnel patrolling the streets.
Schools were closed and residents urged to stay inside.
Security sources said commercial flights would not be operating throughout the day.
Tense residents reported heavy fighting between AMISOM troops and Shabaab militants at a military base outside the capital on Tuesday night.
"There was a heavy exchange of gunfire including anti-aircraft weapons, the attack was targeting the AMISOM base in (the village of) Arbacow," said Dahir Abdikarin, a witness who lives in a nearby village.
Other residents also reported heavy gunfire, while mortar shells landed in several neighbourhoods of Mogadishu.
"The initial information... indicates there were several rounds of mortar shells fired onto the city, we don't have details and the security forces are pursuing the culprits," Somali police commander Ibrahim Mohamed told AFP.