CAIRO — Islamic State militants staged attacks near Baghdad and the Libyan city of Surt on Tuesday, underscoring the group’s persistent strength on both fronts despite a monthslong American-led air campaign against it in Syria and Iraq.

In Libya, the Islamic State captured a critical power plant along the coastal road westward from its stronghold in Surt toward Misurata, a commercial center whose powerful militias are the backbone of a coalition that controls the capital, Tripoli. The loss was the second significant retreat in less than two weeks by the Misuratan militia, which the provisional government in Tripoli had originally sent to expel the Islamic State from Surt.

In Iraq, two gunmen wearing suicide vests attacked a local council building in Amariya al Falluja, a bold incursion into the center of a city about 37 miles southwest of Baghdad. The city is one of the last bastions of government control in Anbar Province after Islamic State militants captured the major city of Ramadi three weeks ago, and Iraqi troops have been battling against the militants on the outskirts of Amariya al Falluja for months.

The extremist group, also known as ISIS or ISIL, is still gaining ground in both countries by filling vacuums created by political deadlock. In Iraq, the Shiite-dominated government in Baghdad has failed to provide convincing evidence of its commitment to equal justice for members of the Sunni minority, spurring sympathy for the Sunni extremists of the Islamic State, while years of corruption and nepotism have hollowed out the armed forces.