BEIRUT — After weeks of setbacks, militants from the Islamic State launched swift counteroffensives Thursday on predominantly Kurdish areas of northern Syria, killing and wounding dozens and setting off car bombs, activists and officials said.

The two-pronged attack on the northeastern city of Hassakeh and the border town of Kobani came two days after Islamic State spokesman Abu Muhammad al-Adnani acknowledged that the group might lose some battles but would not be defeated. The spokesman urged militants to strike back at their foes during the Muslim holy month of Ramadan and “shake the ground beneath them.”

The early morning assault by the Islamic State captured part of Hassakeh, which has long been divided between Syrian Kurds and the military forces of President Bashar Assad.

The militants also hit Kobani, a northern town on Syria’s border with Turkey that had become a symbol of Kurdish resistance against the Islamic State extremists. Kurdish forces, backed by a campaign of U.S.-led airstrikes, drove the militants from Kobani and surrounding villages in January.

Thursday’s fighting in Kobani killed 35 civilians and Kurdish fighters and 14 extremists, according to the Britain-based Syrian Observatory for Human Rights. It was the first time in six months the militants had managed to enter the town, the group said.

The Islamic State militants, wearing Syrian rebel uniforms and carrying flags of the mainstream Free Syrian Army to deceive the Kurdish defenders, launched their attack from areas to the south and west of Kobani, said Redur Khalil, a spokesman for the Kurdish People’s Protection Units, or YPG.

Ghalia Nehme, a commander with the Kurdish Women’s Protection Units, said from Kobani that its fighters were defending a position in the town.

Another Kurdish official in Kobani, Idriss Naasan, said the fighting was intense in the morning but sporadic at midday.

“We hear cracks of gunfire every now and then,” Naasan said around noon.

Kobani-based activist Mustafa Bali said in the evening that Islamic State fighters were still in the city and held several buildings, but that YPG fighters were trying to surround them. He said some Islamic State militants were using civilians as human shields.

Turkey’s Deputy Prime Minister Numan Kurtulmus said on Twitter that four people were killed and 96 people had been wounded in Kobani.

A suicide bomber detonated his car near the border gate, according to two Turkish officials.

Syrian state TV said the extremists crossed into Kobani from Turkey, but Kurtulmus dismissed such allegations as untrue, according to Turkey’s Anadolu news agency.

Islamic State fighters entered the village of Barkh Botan near Kobani, opening fire on civilians and killing 20 people, the Observatory said. Syria’s state news agency SANA said 22 people were killed, including women and children.

The differing casualty figures from Turkish, Kurdish and Syrian sources could not be reconciled in the immediate aftermath of the violence.

Natasha Underhill, an expert on Middle East terrorism from Britain’s Nottingham Trent University, said the re-entry of Islamic State forces in Kobani “comes as a warning to the strength of the group.”

What some may consider a victory over the Islamic State in Kobani could actually be an effort by the group to withdraw and develop a different strategy, she said.

A year ago, the Islamic State captured large parts of Syria and Iraq and subsequently declared an Islamic caliphate on the territory under its control. A major Islamic State attack had been widely expected during Ramadan, which began last week.