Iraqis from a village near Ramadi who fled after the arrival of the Islamic State are shown in an area of eastern Anbar province controlled by pro-government volunteer forces in May. (Ahmad Mousa/The Washington Post)

Six weeks after routing Iraqi security forces from Ramadi, Islamic State militants have entrenched themselves in the city, repairing key infrastructure, managing local government and building up defenses to thwart any attacks.

Their efforts are likely to hamper government attempts to retake Ramadi, which lies about 80 miles west of Baghdad. Iraqi forces and allied militias have not yet mounted a promised offensive, and the delay, residents say, has allowed the Sunni jihadists to cement their role as overlords, supervising everything from local mosques and road repairs to fuel distribution.

The group, known for its brutality, has also long sought to portray itself as a genuine state capable of providing efficiently for its Muslim citizens. From Raqqa and Deir al-Zour in Syria to Mosul and now Ramadi in Iraq, its claim to legitimacy has rested in large part on its ability to run such a state, even as it shocks and alienates residents with punishments such as public beheadings.

When the group’s fighters entered the city, “they seized everyone’s weapons and killed opponents,” said Hisham al-Hashemi, an expert on the Islamic State and adviser to the Iraqi government. “But now there is daily life. There is food in the markets and electricity. It’s like normal.

“As long as the government operation is delayed, it will give [the militants] the opportunity to secure their positions” in Ramadi, he said.

Iraqi security forces defend their positions against Islamic State fighters in Husaybah, five miles east of Ramadi, on June 15. The militant group remains entrenched in the city, capital of Anbar province. (Uncredited/AP)

The capital of the long-volatile province of Anbar, Ramadi has been the site of clashes between the jihadists and government forces for more than a year, even as the Islamic State seized territory elsewhere in Iraq and neighboring Syria. The group cultivated its military prowess on the battlefields of the Syrian civil war.

Ramadi, a predominantly Sunni city where the Islamic State already commanded some support, eventually fell in May after the militants activated local sleeper cells and detonated dozens of car bombs at Iraqi security installations.

After staging a chaotic withdrawal, the government announced an imminent operation to take back the city. Iraqi forces and pro-government militias massed on Ramadi’s outskirts. But the advance quickly halted, and officials now say they need more time.

“If we go too fast, there will be many casualties” among pro-government troops, said Karim al-Nouri, spokesman for the volunteer army known as the popular mobilization forces.

Nouri says Iraqi forces have Ramadi surrounded on three sides, and according to the United Nations, as many as 250,000 of the city’s roughly 500,000 people have fled. But many residents remain.

Meanwhile, the jihadists have consolidated their power there, executing government supporters and breaking Islamic State fighters out of prison. They seized empty houses, rigging some with explosives and using others as sleeping quarters for militants, residents said.

Black-clad jihadists then fanned out across the city, interrogating locals and enforcing strict dress codes for women. The group set up massive screens in at least one public square to broadcast footage of their military gains. Snipers on rooftops control the city’s perimeter, residents say. The local population has bristled at the new restrictions.

“They are always asking: ‘Who are you? Where are you going?’ ” said a 27-year-old Ramadi resident who spoke on the condition of anonymity out of fear for his safety. “Now all of us are required to go to the mosque and pray.”

The Islamic State’s supervision of local mosques is one of the clearest signs of the group’s entrenchment, says Aymenn al-Tamimi, the Shillman-Ginsburg Fellow at the Middle East Forum in Philadelphia.

On June 4, the Islamic State’s newly formed religious committee in Ramadi issued instructions to the mosques of Ramadi. All employees should grow a beard and have good character, the declaration said. And there should be no informal study of the Koran outside the Islamic State-controlled mosques.

The group “places great emphasis on regulating what is and isn’t done in the mosques,” said Tamimi, who is compiling a digital database of Islamic State documents from Iraq and Syria.

But side by side with the intimidation and brutality is the mundane bureaucracy the extremist group has set up here, following the pattern established in the other urban areas it has seized.

Several public works projects have been carried out in the city, including the setting up of neighborhood generators to restore power in the wake of the fighting. Islamic State supporters have also repaired potholes and removed blast walls that had shielded government buildings but were also snarling traffic.

The morning after Ramadi fell, the Islamic State issued a call for all employees of the local hospital to return to work and adhere to their normal schedules, although it is unclear whether the hospital has reopened. The group then distributed fliers throughout the city and online, ordering workers from the Ramadi gas plant to report to the factory at 9 each morning.

“It’s pretty important to them to have a functioning administration and to have vital infrastructure working,” Tamimi said.

Such efforts have indeed restored services, sent people back to work and in some cases won the loyalty of locals otherwise opposed to the group, residents say. Some said many of their neighbors have pledged allegiance to the group since the fighters arrived — whether out of fear, ideological sympathy or the desire for a simple paycheck.

While allegiances are fickle and the Islamic State’s harshness has caused estrangement, if not outright rebellion, among many of its subjects, Ramadi tribal sheikhs opposed to the group fear their position has been undermined by the jihadists’ ability to embed themselves so deeply in the city — and without drawing a serious response from the government.

“They are acting like the permanent government here,” a local man said of the Islamic State. “So of course people have joined them. They have the upper hand.” He also spoke on the condition of anonymity out of fear for his safety.

The group has invested little in the administration of smaller towns or in places where the majority of residents have fled. In Tikrit, for example, which lost most of its population after the group captured it more than a year ago, there were few, if any, services to be managed.

But because Ramadi is the first urban center the group has captured since its advance across northern Iraq last summer, it “is definitely a place they want to administer,” Tamimi said.

Mustafa Salim contributed to this report.

Iraq opens operation to choke off Islamic State lifelines in Ramadi

Chaos in Iraqi forces contributed to biggest Islamic State win this year

Today’s coverage from Post correspondents around the world