JALALABAD, Afghanistan — Islamic State militants in Afghanistan claimed their first attack on a major city on Wednesday, after an assault near the Pakistani Consulate in Jalalabad that killed at least seven members of the Afghan security forces.

The claim, posted on the Telegram channel used by the Islamic State’s central command to announce attacks, was a sign that the main group in Syria and Iraq is increasingly willing to tout its Afghan affiliate as a supported group, even as officials say the level of coordination and contact remains limited.

The attack in Jalalabad, the capital of Nangarhar Province, has also furthered concerns that militants who have broken away from the Taliban and claimed loyalty to the Islamic State were ready to start spreading their brutal campaign into urban areas. The Islamic State cell has fought both the Taliban and the government in Nangarhar over the past year, carving out an ever-bigger area of control, officials say.

The attack, which took place during the busy morning hours as visa applicants lined up near the consulate, began after a suicide bomber detonated his explosive vest near a police vehicle, witnesses said. Then two gunmen wearing police uniforms overran an Afghan government guesthouse near the Pakistani Consulate, and fought Afghan forces for almost three hours.

The attackers were quickly surrounded, though, avoiding extensive civilian casualties in a bustling part of the city at peak hours.

“After the explosion, two men started firing,” said Ismail Khan, 35, an auto-rickshaw driver. “One bullet hit my shawl before I dropped to the ground.”

Image

Two schoolgirls were helped near the Pakistani Consulate in Jalalabad, Afghanistan, after a deadly explosion and a gun fight on Wednesday.CreditNoorullah Shirzada/Agence France-Presse — Getty Images

During the fighting, Afghan security forces found explosives in two other areas on the street and detonated them, officials said. Children trapped in a nearby school were evacuated by the police and local residents.

Gen. Fazal Ahmad Shirzad, the police chief of Nangarhar Province, said that the guesthouse was heavily damaged in the fighting, and that it was still unclear whether that house or the consulate next door was the intended target.

“Seven security forces were killed, and seven security forces and four civilians were wounded,” General Shirzad said.

The assault is the latest in a wave of militant violence striking major cities in Afghanistan since the start of the year. The targets have included a restaurant in Kabul frequented by expatriates; the Indian Consulate in the northern province of Balkh; and a house in Jalalabad that had been the residence of a Pakistani diplomat but was vacant.

The leadership of the Afghan-based affiliate of the Islamic State, also known as ISIS or ISIL, is largely made up of former members of the Pakistani Taliban. But as it has waged its campaign of violence in eastern Afghanistan, the affiliate has adopted the central group’s brand of atrocity and intimidation, carrying out public beheadings and videotaping some of them with slick production values.

Gen. John F. Campbell, the commander of American and NATO troops in Afghanistan, has estimated that there are 1,000 to 3,000 ISIS-affiliated fighters in the country. There have been recent “indications” of fighters from Syria and Iraq coming to help the Afghan affiliates, General Campbell has said.

Naser Kamawal, the deputy head of the Nangarhar provincial council, said the Islamic State-affiliated groups had come under severe pressure from government operations in recent months, particularly in the district of Achin, where they built a base.

“Their turn to attacking the city is to gain attention and to make up for the losses they have suffered,” Mr. Kamawal said. “I see it as a sign of their weakness, and not their strength. The operations have struck big blows to them, otherwise they could have threatened most of Nangarhar.”

Get news and analysis from Asia and around the world delivered to your inbox every day with the Today’s Headlines: Asian Morning newsletter. Sign up here.

A version of this article appears in print on , Section A, Page 6 of the New York edition with the headline: ISIS Claims Responsibility for Assault That Killed 7 Afghans. Order Reprints | Today’s Paper | Subscribe