The Egyptian presidential election will come down to a runoff between Ahmed Shafiq, the final prime minister under deposed president Hosni Mubarak, and Mohamed Morsi, the Muslim Brotherhood’s candidate, according to final results released on Monday.

Farouq Sultan, the head of the presidential election commission, announced the results at a press conference. Morsi garnered the largest share of votes, nearly 5.8 million; Shafiq came in a close second, with 5.5 million.

The frontrunners Mohammed Morsi: 5,764,952 Ahmed Shafiq: 5,505,327 Hamdeen Sabahi: 4,820,273 Abdel Moneim Aboul Fotouh: 4,065,239 Amr Moussa: 2,588,850 The two frontrunners, Morsi and Shafiq, will compete in a runoff election on June 16 and 17.

The third-place finisher was Hamdeen Sabahi, a former parliamentarian who had emerged as a favourite candidate for many of Egypt’s liberals. He received just over 4.8 million votes.

Abdel Moneim Aboul Fotouh, a moderate former member of the Brotherhood, received just over 4 million votes, and Amr Moussa the former Arab League chief, came in fifth with 2.58 million.

Last week’s election was the first free presidential ballot in Egyptian history. Around 23 million people voted, Sultan said, a turnout of roughly 46 per cent.

Sultan said that seven candidates had filed complaints about the results. Four were dismissed because of a lack of evidence; the other three were rejected because candidates missed the filing deadlines.

Several candidates, including Aboul Fotouh and Sabahi, alleged that thousands of military conscripts – who are prohibited from voting – cast ballots during the election. But Sultan rejected that claim, saying the commission found no evidence to support it.

One final challenge remains: On June 11, Egypt’s high court will rule on the constitutionality of a law which bans senior Mubarak-era officials from running for office. If upheld, the law would obviously have serious implications for Shafiq’s candidacy. (Farouq Sultan, the head of the election commission, is also the chief judge on the supreme court.)

‘A return to the old regime’

The frontrunners will spend the next two weeks manoeuvring to win support from the defeated candidates, ahead of the runoff on June 16 and 17.

Two of them, Moussa and Aboul Fotouh, refused to endorse either of the frontrunners during separate press conferences on Monday. Moussa lashed out at both winners, saying that “a return to the old regime is unacceptable, [and] so is exploiting religion in politics”.

Aboul Fotouh also warned against returning to Mubarak-era leadership, and said he would announce his position later in the week. “The most important thing is that people don’t vote for felool,” he said, referring to so-called remnants of the old regime.

Sabahi has not yet announced a position, though it seems unlikely that a candidate who campaigned vigorously against the old regime would endorse Shafiq.

For the liberals who helped spark last year’s revolution, the outcome is a worst-case scenario, forcing them to choose between an Islamist and the scion of Mubarak’s regime. Some have already said they will boycott the runoff altogether.

A slow trickle of protesters, many of them Sabahi supporters, began arriving in Tahrir Square shortly after the results were announced, but Al Jazeera’s Matthew Cassel reported that by late evening, a crowd of roughly two thousand people had gathered.

“..mostly young people…lots of energy,” said Cassel.

He also said that Shafiq’s headquarters had been raided and that the windows were being broken.

Reuters news agency reported that protesters has set fire to Shafiq’s headquarters.

But some didn’t see the utility in returning to the square. Mostafa Mortada, a Sabahi volunteer at the candidate’s headquarters, was fatalistic. “Shafiq is going to be the next president. What am I going to do in Tahrir? The game was not fair.”

Mostafa said Shafiq’s entering the runoff represented the end of the revolution, but also said he would not vote for Morsi and give the Muslim Brotherhood all the levers of power. “Either today or after one year, when Shafiq is president, there will be another revolution,” he said.

Both candidates will be eager to win support from voters who endorsed Aboul Fotouh in the first round, an eclectic mix of religious moderates, conservative salafis, and disaffected former members of the Muslim Brotherhood. Leaders of the Nour party, the largest salafi party, have already said they will vote for Morsi, calling it a “religious obligation.”

Evan Hill and Matthew Cassel contributed reporting from Cairo.