Muhammadu Buhari of the All Progressives Congress opposition party won Nigeria's presidential election Tuesday, defeating the long-ruling Peoples Democratic Party and President Goodluck Jonathan in a historically tight race. Buhari, a 72-year-old former military dictator, won 15.4 million votes against Jonathan's 13.3 million, according to a Reuters tally in all 36 of Nigeria's states.

APC spokesman Lia Mohammed said Nigerians were "witnessing history." Buhari's victory marked the first-ever democratic transfer of power in Nigeria.

"This is the first time in Nigeria that a sitting government will be voted out of power using purely democratic means," Mohammed told Reuters Tuesday at the house in the capital, Abuja, where Buhari was watching the results come in. "The people of Nigeria have taken over."

Buhari, a Muslim from Katsina state, is Nigeria's first president from the predominantly Muslim north since 2010. There were 14 candidates on the ballot, but the race came down to a near-deadlock between Buhari and Jonathan, a 57-year-old southern Christian from the petroleum-rich Niger Delta region. Many northern Muslims support Buhari, while many southern Christians support Jonathan. But Buhari took Lagos state in the south -- Nigeria's commercial hub and most populous city -- as well as crucial wins in three northern states, according to the Associated Press.

Buhari also managed to win votes that went to the Action Congress of Nigeria in the previous election in 2011, according to J. Peter Pham, director of the Africa Center at the Atlantic Council. ACN was one of four opposition parties that merged in 2013 to form the APC, aimed at ousting the PDP, which had won every presidential election since 1999.

Officials of Jonathan's PCP interrupted the vote-counting meeting at the International Conference Center in Abuja Tuesday to petition against the incoming results. Peter Godsday Orubebe, a PDP "collation" (election tally)  agent and former Niger Delta minister, grabbed the microphone at the podium and accused Independent National Electoral Commission Chairman Attahiru Jega of bias, the Premium Times in Nigeria reported.

Political parties in Nigeria have 30 days from the election to legally challenge final results. But Mohammed said the APC had no reason to doubt that Jonathan would admit defeat. "He said several times that he would relinquish power if he was voted out in a free and fair election," Mohammed told Reuters Tuesday.

Although largely peaceful, Nigeria's general elections were marred by technical problems with new biometric voting-card readers and accusations of widespread malpractice. The elections, which were scheduled for Saturday, ran over into Sunday.

Both parties have alleged irregularities and ballot-rigging. The leadership of Buhari's APC condemned the election process in two southern states Monday and demanded the cancellation of results amid allegations of widespread malpractice and vote-rigging, the Daily Independent in Nigeria reported.

Violent attacks by suspected Boko Haram militants also plagued the elections. At least 41 people were killed in attacks during the elections Saturday in northeast Nigeria, causing others to flee the polls. In the southern oil-producing region, thousands of Nigerians protested the alleged killings of opposition campaign workers and voting irregularities, which the INEC chairman has promised to investigate, the Associated Press reported.

Jonathan and Buhari signed a peace accord last week, agreeing to avoid actions that could incite violence during and after the election, according to the Premium Times. But supporters on both sides have threatened to wreak havoc if their candidate loses.

Still, the election was less violent than the last presidential race, when at least 800 people were killed in post-election violence in northeastern Nigeria after Jonathan won 59 percent of the vote against Buhari's 32 percent.

Jonathan's popularity has plummeted in recent years amid concerns over national security, the Boko Haram insurgency and allegations of government corruption. Buhari's campaign focused largely on anti-corruption and strengthening Nigeria's army, which has needed reinforcement from neighboring countries to fight Boko Haram. His pledge to crack down on corruption and build up the security forces helped him pull ahead.

Buhari, who has run for president four times, in the late 1970s was the chairman of the Nigerian National Petroleum Corporation and the federal commissioner -- now called "minister" -- for petroleum and natural resources. He then took power in a military coup in 1983 and ruled until 1985.