The trickle of voters made its way through the deserted streets, the city quiet except for the intermittent boom of mortar fire, a reminder that this is a country at war once more.

About 12 million Iraqis voted Wednesday in the first elections since the withdrawal of U.S. troops, a crucial test for democracy in Iraq amid fears that the western Sunni province of Anbar is slipping from the Shiite government’s grip as the army struggles to put down an insurgency.

Prime Minister Nouri al-Maliki, who is seeking a third term, launched a military offensive to crush hostile Sunni tribesmen and al-Qaeda-inspired militants in Anbar in January. With his popularity flagging among fellow Shiites, he presented himself as the only candidate capable of fighting terrorism, no doubt hoping to rally support.

That gamble looked as though it may have paid off, with an early exit poll Wednesday indicating that his party may have won the largest share of seats in Iraq’s 328-member parliament. The final result will be announced within 30 days, the electoral commission said, depending on the number of appeals.

For many in Anbar, four more years of Maliki — whose party failed to win the 2010 elections but still secured the top seat through political wrangling — is anathema.

“There are two ways to get power — one through elections, the other is through revolution,” Faleh Shahooth, a 67-year-old resident of Ramadi, the capital of Anbar, said as he voted. “We were happy when the old dictator went,” he said, referring to the ouster of Saddam Hussein in 2003, “but democracy has brought a new dictator. If the election produces the same thieves again, then it’s time for revolution.”

Such attitudes raise fears that if political change does not accompany the elections, the growing discontent will fuel the conflict, which is already pushing close to Baghdad.

Turnout was a healthy 58 percent, including overseas voters, according to the Independent High Electoral Commission, but still a decline from the previous vote. More than 9,000 candidates vied for the attention of Iraq’s nearly 22-million-strong electorate — their images dominating billboards, posters and LED screens lining the roads.

With tight security measures, including banning vehicles from the roads, the day progressed largely without incident in Baghdad.

As Maliki voted in the capital’s fortified Green Zone, he called on others to vote as well, as a “slap to the face of terrorism.”

The turnout figures provided by the electoral commission did not include numbers from what it described as “flash point” areas such as Anbar.

“Our indication is that turnout in Anbar is weak,” said Hassan Kadas, a spokesman for the commission.

About 400,000 people have been displaced, making it difficult for people to get to the polls, but violence and political disenfranchisement also are likely to have played a part.

Since the 2010 elections, the Sunni political scene has fractured. Ayad Allawi, a secular Shiite who is on the Iraqiya list, won the largest number of seats in the 2010 elections and had substantial support among the Sunnis. But he is now unlikely to pose a major threat to the incumbent.

Maliki’s biggest challenge comes from his fellow Shiites. Al-Muwatin, or the Citizen bloc, which is headed by a Shiite cleric, is expected to perform strongly, as are the Sadrists, supporters of ­anti-American cleric Moqtada al-Sadr.

Maliki’s State of Law is projected to be the biggest winner but is likely to lose seats, according to an exit poll conducted by Edison Research and EIN in 17 of 18 Iraqi provinces.

In Anbar, poor turnout could benefit pro-government candidates. At a Ramadi polling station in an area loyal to Ahmed Abu Risha, a sheik who heads the tribal forces fighting alongside the government, about 69 percent of registered voters cast ballots.

Here, tribal loyalties are strong, and support is easy to buy, according to Ahmed Khalaf, the governor of Anbar. “It depends on how much money you pay,” he said.

Meanwhile, those displaced and disenfranchised are less likely to have their voices heard.

At a voting place in a school near the city center, Ismail Abed, 47, is not there for the polls but for shelter. He lives in a small room with his wife and five children after being displaced four months ago.

He hopes for change.

“Maliki is against the Sunnis 100 percent,” he said, then adding, “Our country has a lot of oil, but look at me,” pointing to his dusty, worn clothes. “I’d prefer the American occupation; it’s better than Maliki’s occupation.”

Anbar’s residents complain of being cut off from their political representatives, who they say seldom visit the province.

“The old politicians didn’t represent anyone, but we hope the new ones will,” said Ramadi-based Tariq al-Assal, a former police general running for parliament for the first time. “But we are afraid of falsification of the voting.”

Even Iraq’s acting defense minister, Sadoun al-Dulaimi, who is defending his seat in Ramadi, has a bleak view of the democratic process.

“It is very difficult for any society to establish a good democracy when it is surrounded by chaos and by premature institutions,” he said. “We need to clean our country from the terrorists first, and after that the opportunity is there for us to build a nation according to a solid basis.”

Violence is spiraling. About 172 Iraqi soldiers, police officers and armed allied tribesmen died in violence in April, according to an Agence France-Presse tally — out of 777 across the country.

Iraqis are bracing for more after the elections. Fallujah remains in the hands of the Islamic State of Iraq and Syria, which is inspired by al-Qaeda, and anti-government tribesmen, after being seized in January. Any offensive there is unlikely until after a clearer post-election picture emerges, according to Iraqi officials.

That could be months, if the 2010 vote is anything to go by. It took nine months after the election for a government to be formed.

If Maliki emerges as the strongest candidate, he could still have trouble bringing together a workable coalition, having isolated many of his allies, including the Kurds, who once again could play kingmaker.

In 2010, they joined him in a coalition, but since then the relationship between Baghdad and the semiautonomous Kurdish government has nose-dived.

Relations with the Shiite Sadrists also deteriorated to public mudslinging in the weeks preceding the vote.

As polls closed in Anbar, clashes began nearby, and the government fired mortar shells onto a hostile area of farmland.

“Is this the democracy that so many martyrs have sacrificed themselves before?” Shahooth said as he hobbled out of the polling station with the help of a cane. “I hated Saddam, but there’s no stability, no security, no jobs. Not just in Anbar, in all of Iraq.”