BEIRUT, Lebanon — Hours after they swept into the Syrian city of Palmyra last week, Islamic State militants carried out scores of summary executions, leaving the bodies of victims — including dozens of government soldiers — in the streets.

Then, residents say, they set about acting like municipal functionaries. They fixed the power plant, turned on the water pumps, held meetings with local leaders, opened the city’s lone bakery and started distributing free bread. They planted their flag atop Palmyra’s storied ancient ruins, and did not immediately loot and destroy them, as they have done at other archaeological sites.

Next came dozens of Syrian government airstrikes, some killing civilians. That gave the Islamic State a political assist: Within days, some residents had redirected the immediate focus of their anger and fear from the militants on the ground to the warplanes overhead.

In Palmyra, the Islamic State group appears to be digging into power in a series of steps it has honed over two years of accumulating territory in Iraq and Syria.