Throughout Iraq, fear gave way to defiance Sunday as voters, even in the most volatile areas, cast ballots in landmark parliamentary elections that militants tried their best to disrupt with dozens of explosions that shook Baghdad even before the polls opened.

By the end of the day, at least 38 people were dead and more than 80 were wounded throughout the country, Iraqi authorities said, including 25 casualties in a Baghdad apartment building that collapsed on sleeping families in an early-morning blast.

The despair at the scenes of violence stood in stark contrast to triumphant moments that unfolded elsewhere as Iraqis dipped their fingers in purple ink and cast ballots in elections that were billed as the first organized and secured by Iraqis since the US-led invasion of 2003.

EDITORIAL: High stakes, shaky hopes for Iraq election

"It's in the Iraqi nature to rise to a challenge, and we were challenged," said Younis Gomar, the head of a polling center in Baghdad.

Congrats from Obama

"We mourn the tragic loss of life today, and honor the courage and resilience of the Iraqi people who once again defied threats to advance their democracy," President Obama said in a statement of congratulations.

Later, speaking in the White House Rose Garden, Obama added that by the end of August, "our combat mission will end" and said, "By the end of next year, all US troops will be out of Iraq."

The US military, however, played a crucial behind-the-scenes role Sunday, a fact that calls into question whether Iraq's security forces will be able to lock down their country on similar high-stakes occasions after the American withdrawal.

After months of joint planning with Iraqis, American attack helicopters provided air support; American drones supplied aerial intelligence; American teams provided route clearance and escorts for international monitors, and American forensics experts investigated explosives found near polling stations.

Now the hard part

With Election Day out of the way, Iraqis now face what could be an even more gargantuan task. None of the top vote getters is expected to win an outright majority, ensuring weeks and probably months of horse-trading before a new government is formed.

Analysts and foreign diplomats agree that the coalitions most likely to win are the self-proclaimed nationalist slate led by Iraq's incumbent Prime Minister Nouri al Maliki, a Shiite Muslim; the secular, mixed-sect ticket of former premier Ayad Allawi; and an alliance of Iranian-backed Shiite candidates and religious parties that was widely predicted to trail the first two in all but the most conservative Shiite parts of the country.

Once again, however, Kurdish parties in semi-autonomous northern Iraq are likely to hold the balance of power because Arab parties will need their support to assemble a majority in the 325-seat Iraqi parliament.

Results to come

Reliable information on Sunday's results and voter turnout isn't expected for at least another day, possibly longer, according to the United Nations mission in Iraq. That didn't stop various candidates or their representatives from claiming victory on television or publicly hinting at electoral fraud, perhaps in efforts to position them for battle in case they didn't fare well.

It will take Iraqi election officials days to compile allegations of fraud or irregularities, but among the most common violations cited Sunday were candidates campaigning in polling centers, heads of households voting for other family members, and security forces intimidating voters to pick specific candidates.

In the southern Shiite holy city of Najaf, some 3,000 residents didn't find their names on the voter rolls, said the province's Gov. Adnan al Zurfi, who called it "a breach of law." Similar complaints emerged in the Kurdish city of Suleimaniyah, as well as the ethnically diverse city of Kirkuk, where Sunni Arabs and Sunni Kurds are battling.

At least 5,000 internally displaced people — Iraqis who were forced from their homes in the sectarian bloodshed of recent years — didn't find their names registered in Diyala province, according to the election commission there. Tens of thousands of displaced Iraqis needed special permission to vote outside their home provinces.

"It was a fierce battle with the Iraqi people on one side and all the other powers on the other, and the Iraqi people came out victorious. By all other powers, I mean the establishment, the bureaucracy, the insurgents, the incompetents," said Mohannad al Kinani, the head of Ayn al Iraq, an independent Iraqi group that monitored the elections. "The Iraqi people have shown that they are strong and not easily subjugated, and that they know what they want . . . . It is time for the occupation to pack its bags and leave."

Iraqis provided security

Despite the backstage American role, the face of security Sunday was decidedly Iraqi — unlike during the last parliamentary vote in 2005 — with no American patrols visible on the streets, and Iraqi forces manning checkpoints across the country.

Iraq also shut down airports and sealed its borders ahead of the vote. The heavy security presence and a ban on most vehicle traffic were credited with preventing car bombings.

Most of the explosions Sunday came from dozens of water bottles that had been packed with crude explosives such as ammonium nitrate and ammonium phosphate and left in garbage cans and near curbs along routes to polling stations, according to the U.S. military.

"Think of 2-liter Coke bottles. Then they put explosives inside with a timer, and use a remote-control detonator," said Maj. Gen. Stephen Lanza, a spokesman for U.S. forces in Iraq. "It really is a crude device."

Lanza said the water-bottle bombs caused most of the early-morning booms that woke up Baghdad residents before 7 a.m. Sunday and continued in quick succession until early afternoon. He said the weapons were designed more for psychological impact than for lethality.

The blasts were so loud and so frequent that by early afternoon many Iraqis had stopped flinching. Outside one polling station in Baghdad, an emergency worker on standby got laughs from voters as he ululated and danced outside his ambulance, saying, "Thank God, no explosions here so far!"

In cities such as the former Sunni insurgent stronghold of Fallujah in the west and the restive city of Mosul in the north, the blasts were so terrifying that clerics used mosque loudspeakers to reassure voters that they'd be protected if they came to polling centers.

Voters in those cities, with large Sunni populations, already were skeptical of the whole process. Sunnis boycotted the 2005 election, a move that left them sidelined and with scant representation in the current government, which is dominated by Shiites and Kurds. This time, Sunnis voted, mainly for the bloc headed by Allawi, a secular Shiite, according to interviews with voters in several cities.

"I had rejected elections on principle since 2003, but a few days ago I decided to participate," said Samir Qaddouri al Jumeili, 34, a health worker and Allawi supporter from majority Sunni Anbar province. He said he expected to find plenty of room for fraud, but was "pleasantly surprised" by the relatively transparent process.

The cause of the deadliest blast, the one that flattened the apartment building in the Shaab neighborhood of north Baghdad, remains a mystery. Lanza, the U.S. military spokesman, said the building either was rigged with explosives for some unknown reason or was the site of a bomb-making operation.

The building came down at 7 in the morning, and by late afternoon Iraqi rescue workers were still using cranes, bulldozers and their bare hands to reach a woman whose faint cries could be heard from under the rubble. She finally was brought out alive, a happy ending that wasn't shared by many other residents. At least 25 people died and another 19 were injured in the explosion, according to the Iraqi interior ministry.

A elderly woman sat on a piece of debris, sobbing into her black robes over the deaths of her daughter and four grandchildren. One of the corpses was still trapped inside. A uniformed Iraqi policeman had to be supported by fellow officers upon learning that his wife and three young children had perished. He'd left them sleeping early in the morning to report for election security duty, said his brother, Abbas Fawzi.

"It surpasses words," Fawzi said, his legs and hands still covered in dust from his attempts to dig out the bodies.

A few yards away, a dazed man who'd already watched his wife's body pulled from the rubble awaited word on the fate of his 12-year-old daughter, who hadn't been found. An older relative, Mohsen Allawi, prayed with him, and then grew angry at the security breach that had allowed such an attack.

"Is this how cheap Iraqi blood is?" Allawi said, his voice furious. "Is this the dream of the Iraqi people?"

---- Issa is a McClatchy special correspondent. Special correspondents Mohammed al Dulaimy and Laith Hammoudi in Baghdad, Ali Abbas in Mosul, Yassine Taha in Suleimaniyah, Jamal Naji in Fallujah, Qassim Zein and Ali al Basri in Najaf and a reporter who isn't named for security reasons in Baquba contributed.

---- Follow us on Facebook and Twitter.

MORE FROM MCCLATCHY

Obama: The future of Iraq belongs to the people of Iraq

LIVE BLOG: Election Day in Iraq

A Q&A on Iraq's March 7 parliamentary elections

Defying bombers, Iraqi security forces vote en masse