Politicians are voting in a high-security compound at an airport in the Somali capital Mogadishu to elect a president for the unstable east African state.

Growing evidence of the systematic purchase of votes risks undermining Wednesday’s long-awaited poll, which has been described as a “way station” to political stability and full democracy.

Critics say the election – the most extensive democratic exercise for decades – has entrenched divides between the country’s many traditional clans and encouraged graft, some fuelled by Middle Eastern and regional powers seeking to secure the election of candidates seen as favourable to their interests.

Somalia, which faces a tenacious insurgency by Islamic militants and a looming famine, was among seven Muslim-majority states named in Donald Trump’s contentious executive order suspending immigration last week. It is a big recipient of international humanitarian aid.

Some involved in the vote remain confident, calling it an important step for the nation. “We are well-prepared to elect a new president. It’s a test for a maturing democracy,” said Ahmed Ali, a Somali parliamentarian.

Michael Keating, the UN special representative for Somalia, described the poll as a “political process with electoral features” that was “pretty brave to do”.

Somalis walk past a campaign poster on the eve of presidential elections in Mogadishu. Photograph: Farah Abdi Warsameh/AP

The complex process of selecting a president began months ago with 14,000 elders and prominent regional figures choosing 275 MPs and 54 senators. These will now choose whether to back President Hassan Sheikh Mohamud for a second five-year term or one of 21 rivals. It is likely to take several rounds before a winner is declared.

“Though it doesn’t solve Somalia’s many challenges, it’s an expression of some political progress … and does highlight a vibrant electoral and political engagement,” said Ahmed Soliman, an east Africa expert at Chatham House.

“What we are seeing is the selection of a president to take the country forward … If you look at the region, and countries such as Sudan, Ethiopia, Djibouti or Eritrea, there is a clear contrast. The election is impressive in the context.”

In Mogadishu, the capital, streets were deserted with many residents following the voting on television. Ali Abdi Haji, a 23-year-old student, said he had never experienced an election.

“Today is great day for me and for people in Somalia. All I can do today is just watch TV and pray for the country so we can have a good leader who is committed to make this country peaceful and democratic,” said Haji, watching the broadcast with his family in their home in the Hodan district of Mogadishu.

Waris Nur, 34, a businesswoman, said she wanted a leader who “can make the country peaceful and without terrorism”.

Al-Shabaab, the Islamic militant movement that has fought for power in Somalia since 2009 and is affiliated with al-Qaida, has been slowly driven out of its key strongholds in a campaign by regional and Somali troops but still launches frequent attacks in Mogadishu and elsewhere.

An attack on a military base 10 miles (15km) south of Mogadishu on Tuesday was repulsed while several mortar bombs in Mogadishu on the same day caused no casualties. On Wednesday morning, the group stormed a hotel in the semi-autonomous Puntland region, further north up the coast, killing four guards.

The threat from al-Shabaab forced the government and its western backers to scrap a plan to give each adult a vote. Officials decided that the challenge of securing polling stations across the country of 10 million people was insurmountable.

Hassan Sheikh Mohamud has the support of about a third of lawmakers. Photograph: Isaac Kasamani/AFP/Getty Images

Keating, the UN official, said reports that al-Shabaab had allowed the poll to go ahead were wrong. “They are not shrugging their shoulders and ignoring the election. That is rubbish,” he said. “Al-Shabaab have tried repeatedly to disrupt it. They have targeted MPs and electoral sites. They do not like this. It goes against everything they stand for.”

However, the biggest problem for the polls may be allegations of systematic corruption. Rival presidential candidates have accused each other of buying the loyalty of lawmakers, and local anti-corruption campaigners say tens of thousands of dollars have been handed to individuals to secure support in the vote.

“This is probably the most expensive election, per vote, in history,” the Mogadishu-based anti-corruption group Marqaati said in a report released on Tuesday.

Hasan Abdurahman Mohamed, 56, a university lecturer in Mogadishu, described being shown a cheque for $10,000 (£8,000) by one new MP who asked him to lobby other MPs in favour of a particular candidate.

Hashi Siad, 67, a clan elder, said presidential candidates were “in a hurry to pay bribes to MPs and elders and even lobbyists who can have some kind of influence”. Some of the candidates will pay as much as $50,000, he said.

Hours before voting was due to start, the chairman of the presidential election committee, Abdirahman Beyle, told MPs they would not be allowed to enter the voting hall with their mobile phones. Beyle said the measure was to prevent politicians taking pictures of their ballot papers to prove to those who had given them money that they had voted as instructed.

Mohamed Omar, an MP, said, as a devout Muslim he had rejected a series of bribes but knew of other new parliamentarians “who were paid big money”.

Western donors, who have often criticised Mohamud’s government for corruption, say the vote is far from perfect but marks a modest step forward from 2012 when just 135 elders picked the lawmakers, who chose the president.

They also point to the levels of female participation: almost a quarter of elected MPs are women.

Waris, the businesswoman, said she also hoped for “a leader who can protect our women rights because women are the largest population in our country and they are not given equal rights”.

Fadumo Dayib. Photograph: Jussi Nukari/AP

Fadumo Dayib, a Somali politician who briefly campaigned as a presidential candidate last year, said female MPs would “not stand a chance” if they tried to assert themselves.

“They could have had women associations as voters. Instead the vote was given to clan elders who just selected the women to represent their interests. If [the women] do not do what they are told they will be ostracised … The international community could have asked for much, much more. It has lost a great opportunity,” Dayib said.

Mohamud, who has led the country since 2012 in the effort to rebuild Somalia after more than two decades of war and chaos, has the support of about a third of lawmakers, analysts say, giving him an edge but not a guarantee of victory.

A win for the incumbent would not please western powers. British parliamentarians reported last year that “there is a tangible sense amongst western donors that President Mohamud’s government has not been the fresh start that Somalia needed”.

A key rival is Sharif Sheikh Ahmed, a conservative who was a leader of the Union of Islamic Courts, a hardline grassroots clerical movement that took control of much of Somalia 10 years ago.

The election, which has been largely paid for by the US and EU states, has provoked fierce interest from rival Middle Eastern powers keen to extend their influence in a strategically important part of the world. The United Arab Emirates, Qatar, Turkey and Saudi Arabia have all been accused of funding the campaigns of specific candidates and thus indirectly fuelling corruption.

The US and other international powers have pressed Somalia to move ahead with elections as an important symbol of recovery. In the past decade, the US has given $1.5bn in humanitarian aid and another $240m to support Somalia’s political and economic recovery, and $196m in overall funding is planned for 2017.

“There are a lot of problems [in Somalia] of course, but it is not a place falling apart, it is a place coming together,” said Keating.