Somali MPs were choosing a president under tight security on Wednesday, with roads closed and residents urged to remain indoors over fears of an attack on the capital by al-Shabab.

A protracted vote began on Wednesday after 14,000 elders and prominent regional figures chose 275 members of parliament and 54 senators, who in turn now choose whether to back President Hassan Sheikh Mohamud for a second term or one of 21 rivals.

Fears of attacks by al-Shabab, an armed group, have limited the election to the country's legislators, who will vote at a heavily guarded former air force base in the capital, Mogadishu.

Earlier on Wednesday, gunmen stormed a hotel in the semi-autonomous Puntland region, killing four guards.

READ MORE: Somalia beefs up security ahead of presidential vote

Several rounds of voting are expected to narrow down the large field of candidates. One candidate dropped out on Wednesday before the voting started.

Al Jazeera's Mohammed Adow, reporting from the capital Mogadishu, said sources within the parliament had confirmed that huge sums of money were paid by some of the candidates and rival presidential candidates have accused each other of buying the loyalty of MPs, drawing furious denials.

"One member of the parliament told me that he received thousands from one of the presidential candidates," he said. "There is lot at stake here. This election is supposed to bring leadership that heals the country but if corruption plays an important role, many doubt whether Somalia is going to be on the right road."

President Mohamud, who has led the country since 2012 as it tries to rebuild after more than two decades of war and chaos, has the support of about a third of MPs, political analysts say, giving him an edge but not a guarantee of victory.

The threat from al-Shabab, who regularly launch attacks in Mogadishu and elsewhere, meant the government and its Western backers to go back on a promise to give each adult a vote due to what they say was the challenge of securing polling stations.

"We have tightened security and have confidence the new politicians will elect or re-elect a candidate they believe can save Somalia," Major Hussein Nur, a police officer, told the Reuters news agency.

READ MORE: Crisis in the Horn of Africa - Somalia's Famine

In 2012, just 135 elders picked the MPs, who chose the president.

"It tells us that we are in the midst of a long transition and in theory, based on the provisional constitution we should be having one-person-one-vote election this year, but that hasn't been possible because of security constraints but also because the government did not focus on preparing the ground," Matt Bryden, the Chairman of Sahan Research and Development Organization, a political think-tank covering the Horn of Africa, told Al Jazeera.

"This is an ad hoc political compromise agreed by Somalian political leaders, which is simply a way of continuing a transition and giving us four more years in which to consolidate architecture of the new Somalian state."

The airport, where the vote is taking place, is guarded by the African Union peacekeeping force AMISOM and is surrounded by high concrete barriers to protect it from attack.

UN agencies and foreign embassies are also located in the compound.

Al-Shabab, which ruled Somalia for several years, has been slowly driven out of its major strongholds in a campaign by AMISOM and Somali troops.

But its fighters continue to launch regular gun and bomb attacks in their effort to topple the government.