Nigeria’s president Muhammadu Buhari has been declared the winner of the country’s election after results showed that he claimed 56% of the vote.

With ballots from all 36 states counted, Buhari’s All Progressives Congress (APC) garnered 15.2m votes compared with 11.3 m for Atiku Abubakar’s People’s Democratic party. The election turnout was 35.6 percent, the electoral commission said, which compared with 44% in the 2015 presidential election.

“Muhammadu Buhari of the APC, having satisfied the requirement of the law and scored the highest number of votes is hereby declared the winner,” Mahmood Yakubu, chairman of the Independent National Electoral Commission (INEC), told election officials and reporters in the early hours of Wednesday.

Buhari won in 19 states – including the two most populous, Lagos and Kano – while Abubakar was victorious in 17.

To win in the first round, the victor must get at least a quarter of the votes in two thirds of the states, plus an overall majority, and Buhari appeared to have won enough to avoid a runoff.

Bashir Ahmad, one of Buhari’s adviser’s, posted on Twitter a picture of the president laughing and with the slogan “BuhariHasWon”.

A message posted on Buhari’s Twitter feed late on Tuesday showed him smiling and surrounded by applauding staff at his campaign office.

“I met the very hardworking members of our team, many of them young people, and was briefed on the performance of our party so far in the Presidential Elections. I am very proud of what has been accomplished,” he said on Twitter.

But the opposition People’s Democratic party (PDP) rejected the result and threatened to take legal action, saying that the ruling All Progressives’ Congress had manipulated the vote.

“I’m not aware of any meeting of the PDP legal team, but I know there are concerns laid to the INEC [electoral commission] chairman , based on promises he made to Nigerians on the conduct of the elections,” Kola Ologbondiyan, PDP spokesman, said. “When he addresses those concerns, then we will know what to do.”

Babatunde Fashola, a minister and the campaign director for election monitoring, told the Associated Press that they were preparing for the president to give his acceptance speech and celebrate. Dozens of supporters began dancing outside party headquarters in Abuja.

He said Atiku, who is known by his first name, should accept his loss gracefully and provide evidence to back up claims that the ruling party manipulated the results of Saturday’s vote.

The election was delayed at the last minute by a week and, since it was held, 47 people have been killed, according to the monitoring organisation the Situation Room.

Reports of vote-buying, multiple failures with the card readers supposed to accredit voters and extremist attacks in the north east marred the election. Many polling stations opened late and, in some, voting continued on Sunday.

Shortly before the election, Buhari suspended the chief justice Walter Onnoghen, who heads the supreme court and would have ruled on any dispute over the results. The president’s move was widely criticised as a “calculated attempt to gain some electoral advantage” in the case of a legal challenge.

Adewunmi Emoruwa of The Election Network said the election fell short of expectations. “The numbers alone are indicting. We have already witnessed a record number of cancelled votes – more than double the numbers from the previous poll – and which is only a reflection of the widespread irregularities across every part of the country. We all observed as thugs had a field day unleashing terror on demographically profiled voters, which led to the suppressed turnout that has been recorded.”

Buhari and Atiku are both northern Muslims in their 70s who have long been in politics. Buhari is seen by many as a strict, inflexible but personally incorruptible figure, while many hoped Atiku, a wealthy businessman and former vice-president, would enact policies to help boost Nigeria’s struggling economy.

Buhari’s popularity dropped over the course of his term, because of his perceived inability to deal fairly with government corruption – he was accused of largely targeting his opponents for prosecutions – and his failure to deal with the many threats facing Nigerians. The north-east region is especially dangerous, because Boko Haram and its offshoot Islamic State West Africa Province still wield considerable might.

It would be unusual for a presidential election to be won by a candidate not backed by a powerful cabal of former generals that includes former presidents Olusegun Obasanjo and Ibrahim Babangida.

Buhari narrowly won Lagos, where only 1.1 million of an estimated 20 million residents voted, as well as the pivotal state of Kano, despite the fact that its powerful ex-governor Rabiu Kwankwaso switched from Buhari’s APC to the PDP last year.