BAGHDAD— Former U.S.-backed prime minister Ayad Allawi and his secular, anti-Iranian coalition narrowly won Iraq's parliamentary elections in final returns Friday, edging out the bloc of Prime Minister Nouri al-Maliki, who angrily vowed to challenge the results.

If Allawi's coalition remains on top, it will get the first opportunity to form a parliamentary majority and Iraq's next government, and complete his emergence from what once appeared to be the political graveyard. But they do not automatically mean that he will become prime minister, and the narrow margin sets the stage for months of political wrangling.

A coalition including anti-American cleric Muqtada al-Sadr finished a strong third and could end up playing the role of kingmaker. Kurdish parties also could be crucial in determining who will rule the oil-rich Arab nation of 28 million people.

Allawi told cheering supporters at his Baghdad headquarters he wants to help build a stable region that would help "achieve prosperity for (Iraq's) people."

"On this occasion, I'd like to congratulate the Iraqi people and extend the hand of friendship to all neighboring and world countries," said Allawi, a secular Shiite politician who appealed across sectarian lines to minority Sunnis who have been out of power since the downfall of Saddam Hussein.

Baghdad's Sunni neighborhoods, the site of vicious sectarian fighting just a few years ago, erupted in cheering, honking of horns and celebratory gunfire in support of the man they have endorsed as their own.

"Today is a historic and joyful day which will witness a change for the sake of Iraqi people," said Hameed Marouf, an Allawi supporter in Azamiyah.

But the results released Friday portend an ugly, protracted battle. No coalition is close to the 163 seats needed to control the 325-seat parliament.

Allawi's Iraqiya coalition won 91 seats to 89 for al-Maliki's State of Law bloc. The Iraqi National Alliance, a Shiite religious group dominated by al-Sadr's followers, won about 70 seats, and Kurdish parties picked up 51.

Regardless of who eventually comes out on top, the results of the March 7 elections suggest that millions of Iraqis are fed up with a political system that revolves around membership in one of the two major Islamic sects.

Iraqiya's win also shows that many Iraqis are suspicious of Iranian influence. Allawi was widely seen as closer to the region's Arab governments than to neighboring Shiite Iran.

The next prime minister will lead a government that presumably will be in power when the U.S. completes its scheduled troop withdrawal from Iraq next year. There has been fear among some in the West that a U.S. withdrawal would effectively leave Iraq as an Iranian puppet.

Al-Maliki, the U.S. partner in Iraq for the past four years, announced in a nationally televised news conference that he would not accept the results.

Gesturing angrily, he said he would challenge the vote count through what he described as legal process. By law, he would have until Monday to register his complaints with the election commission.

The prime minister submitted a request to the country's Supreme Court for clarification on the definition of the biggest bloc in parliament. Under the constitution, the president tasks that bloc with trying to form a government.

In what appears to be a non-binding legal opinion made public Friday, the court left open the possibliity that the biggest bloc in parliament could be a coalition formed after the election, not necessarily the biggest coalition as it existed on Election Day. But it was not clear what effect that decision might have and it would be sure to face challenges from Allawi's followers and others.

After the complaints are addressed, the results may be revised and then finally submitted to Iraq's Supreme Court, which must ratify them. The entire process could take weeks.

Al-Maliki and his supporters had previously called for a recount, saying there had been instances of vote rigging and fraud. But election officials had refused, and international observers have said the election was fair and credible.

The top U.N. official in Iraq, Ad Melkert, called on all sides to accept the results. That sentiment was echoed by U.S. Ambassador Christopher R. Hill and Gen. Ray Odierno, the top U.S. military official in Iraq, who praised what they described as a "historic electoral process," and said they support the finding of election observers who found no evidence of widespread or serious fraud.

Hours before the results were announced, two bombings near a restaurant in a city north of Baghdad killed at least 40 people — a harbinger of a spike in violence that many Iraqis fear could accompany lengthy negotiations on forming a coalition government.

An increase in attacks could complicate U.S. plans to reduce troop levels from 95,000 to 50,000 by the end of August. All U.S. forces are slated to leave Iraq by the end of 2011.

The election results represent a spectacular turnaround for Allawi, a doctor who has spent much of his life in London as a leading member of the opposition to Saddam's regime.

He served as the U.S.-backed prime minister in Iraq from 2004 to 2005. During that time he won enemies for his backing of U.S. military campaigns in both the Sunni stronghold of Fallujah and the Shiite town of Najaf. More recently, many praised his stand as a sign of his willingness to deal harshly with militant groups, but in the 2005 election his party was trounced.

Allawi will face significant challenges finding allies.

For starters, many of his Sunni backers are anathema to the country's Kurdish population, who are considered key to any coalition. The Kurds have often clashed with Sunni Arabs in disputed territories that the Kurds claim stretching from the Syrian border to the Iranian border.

In the northern Ninevah province, one of Allawi's main backers — Osama al-Nujaifi — is viewed with almost vitriolic hatred by Kurds, who might lobby for Allawi to dump him and others before they would consider joining his coalition.

Many Shiites also view Allawi's Sunni allies as little more than Saddam-era holdovers hoping for a return to the Baathist regime who once ruled the country.

Followers of al-Sadr, meanwhile, have a deep-rooted distrust of al-Maliki, who routed their militias and jailed thousands of their supporters. That could help draw them to Allawi's coalition.

Allawi, who once fought off an assassination attempt by a machete-wielding assailant believed to be sent by Saddam, has shown a keen instinct for political survival.

In the current campaign, Allawi's bloc provided a stark contrast to the religious orientation of the two large, Shiite-led coalitions led by the Iranian-backed Supreme Islamic Iraqi Council, or SIIC, and al-Maliki's Dawa Party. His political rallies were Western in style, with music and dancing, while the religious parties held more sober rallies.

Al-Maliki, known as a hardline Shiite during his first couple of years in power, has more recently transformed himself into a law-and-order nationalist who has occasionally reached out to Sunnis, who make up about 15-20 percent of Iraqi's population.

While trying to re-establish a strong central government — most notably by routing a Shiite militia that ruled parts of Baghdad and Iraq's second-largest city, Basra — al-Maliki has also alienated many key constituencies. His support for a ban of hundreds of candidates with alleged ties to Saddam's regime severely undercut any support he had from Sunnis, who felt the ban unfairly targeted their candidates.

Friday's results were based on numbers released by the election commission and compiled by The Associated Press.

Allawi fared well in provinces with significant Sunni populations such as Ninevah, Anbar, Salaheddin, and Kirkuk, while al-Maliki won more support in areas with significant Shiite populations such as Baghdad, and much of the Shiite south.

Significantly, though, Allawi did better in Shiite areas than al-Maliki did in Sunni regions, and that proved key to his victory. (AP)