Boko Haram extremists killed 41 people, including a legislator, and scared hundreds of people from polling stations but millions voted across Nigeria Saturday in the most closely contested presidential race in the nation's history.

All the Boko Haram attacks took place in northeastern Nigeria, where the military Friday announced it had cleared the Islamic extremists from all major centres, including the headquarters of their so-called Islamic caliphate.

Nearly 60 million people have cards to vote, and for the first time there is a possibility that a challenger can defeat a sitting president in the high-stakes contest to govern Africa's richest and most populous nation.

The front-runners among 14 candidates are President Goodluck Jonathan and former military dictator Muhammadu Buhari.

Voters also are electing 360 legislators to the House of Assembly, where the opposition currently has a slight edge over Jonathan's party.

Nigeria's political landscape was transformed two years ago when the main opposition parties formed a coalition and for the first time united behind one candidate, Buhari. Dozens of legislators defected from Jonathan's party.

Polling will continue Sunday in some areas where new machines largely failed to read voters' biometric cards, said Kayode Idowu, spokesman of the Independent National Electoral Commission. That includes some areas of Lagos, a megacity of 20 million and Nigeria's commercial capital on the Atlantic coast.

Vote counting by the light of cellphones

In other areas, vote counting ended Saturday night, with blackouts that are routine forcing some officials to count by the light of vehicles and cellphones.

Earlier, before dawn, Boko Haram extremists invaded the town of Miringa in Borno state, torching people's homes and then shooting them as they tried to escape the smoke. Twenty-five people died in the attack, Borno state Gov. Kashim Shettima told a news conference in the city of Maiduguri.


Nigerian, Chadian and Niger forces have driven militants out of a string of towns in simultaneous offensives over the past month. (REUTERS)

"They had sent messages earlier warning us not to encourage democracy by participating in today's election," said Mallam Garba Buratai, a Miringa resident who witnessed the attack.

Nigeria's home-grown Islamic extremists say democracy is a corrupt Western concept and point to the endemic corruption as a reason to do away with it in favor of an Islamic caliphate.

Another 14 people were killed in extremist attacks on the town of Biri and Dukku, in Gombe state, according to police and local chief Garkuwan Dukku.

Among the dead was a Gombe state legislator, Umaru Ali, said Sani Dugge, the local campaign director for the opposition coalition.

Two voters were killed in Boko Haram attacks on polling stations in the twin Gombe towns of Birin Bolawa and Birin Fulani, according to police. Witnesses said the gunmen yelled that they had warned people to stay away from the polling stations.

In four other northeast towns, gunmen drove in and fired into the air, frightening people to flee into the bush and disrupting any voting, police said.

Thousands of people, among more than 1.5 million forced from their homes by the Islamic uprising, lined up to vote at a refugee camp in Yola, capital of northeast Adamawa state and home to as many refugees as its 300,000 residents.

Refugee Elzubairu Ali does not know when she will be able to return to her home.

"We have to wait for the time when the Nigerian army will totally wipe them (Boko Haram) out before we can go back," she said after voting.

The failure of Jonathan's administration to curb the insurgency, which killed about 10,000 people last year, has angered Nigerians in the north.

International outrage has grown over another failure — the inability to rescue 219 schoolgirls kidnapped by Boko Haram nearly a year ago. The extremists have abducted hundreds more since then, using them as sex slaves and fighters.

Nervous foreign investors are watching as Nigeria is Africa's largest destination for direct foreign investment though its oil-dependent economy is hurting from slashed petroleum prices.

The Islamic uprising has exacerbated relations between Christians like Jonathan, who dominate the oil-rich south, and Muslims like Buhari, who are the majority in the agricultural and cattle-herding lands of the north. The population of 170 million is almost evenly divided between Christians and Muslims.

Some 1,000 people were killed in rioting after Buhari lost to Jonathan in the 2011 elections. Thousands of Nigerians and foreign workers have left the country amid fears of post-election violence.

In 2011, there was no doubt that Jonathan had swept the polls by millions of votes.

Now the race is much closer. Results are expected 48 hours after voting ends.