ERBIL, Iraq — Facing a broad offensive from Iraqi and Kurdish troops, the Islamic State has defended villages around Mosul with its signature tactics of suicide car attacks and roadside bombs. But on Friday morning, militants attacked the strategic oil city of Kirkuk, far to the east, in the manner of a conventional army.

Dozens of uniformed Islamic State fighters, some of whom were believed to be part of sleeper cells and others who drove into the city in vehicles, assaulted Kirkuk, setting off gun battles in the heart of the city that lasted from dawn into the night. Imams shut down all mosques in the city, canceling Friday Prayer, as the city was turned into an urban battle zone that was livestreamed for much of the day by Kurdish news outlets.

The battle scenes and the sound of automatic gunfire in Kirkuk were reminiscent of the Islamic State’s brazen march across northern Iraq two years ago, when Mosul and other cities were first seized by the group.

The group’s sudden counterattack on Friday also involved suicide bombings on police positions inside the city, and gunmen later took up positions in a mosque, a school and a hotel, and on top of other buildings. The government quickly instituted a curfew, ordering civilians to shelter indoors.