BEIRUT — Islamic State militants entered a major Syrian opposition stronghold in the country’s north Saturday, clashing with rebels on the edges of the town as the extremist group builds on its most significant advance near the Turkish border in two years – even as it loses ground elsewhere in the country and in neighboring Iraq.

The town of Marea, just north of Aleppo, has long been considered a bastion of relatively moderate Syrian revolutionary forces fighting to topple President Bashar Assad. The assault underlined the weakness of the groups fighting under the loose banner of the so-called Free Syrian Army that have been struggling to survive.

More than 160,000 civilians have been trapped by the fighting, which also forced the evacuation of one of the few remaining hospitals in the area, run by the international medical organization Doctors Without Borders.

On Saturday, Islamic State fighters staged two suicide bombings targeting “opposition forces” near Marea, the Islamic State said via its news agency, Aamaq.

After the suicide bombings, militants entered Marea and fighting began inside the town, according to the Syrian Observatory for Human Rights, a Britain-based opposition media outfit that tracks Syria’s civil war.

Dr. Abdel Rahman Alhafez, who heads one of the last remaining hospitals in Marea, said the town was encircled and his hospital under threat since Friday.

“We need urgent protection for the hospital or a way out,” he said in an emailed statement.

Syrian army warplanes and helicopters, meanwhile, pounded other opposition-held towns in Aleppo province Saturday, putting a further strain on embattled rebels fighting Assad’s forces.

Islamic State’s territorial gains around Marea and Azaz, both critical rebel bastions north of Aleppo, are a blow to the Turkey- and Saudi-backed opposition fighters who have been struggling to retain a foothold in the region while being squeezed by opponents from all sides. They also demonstrated the Islamic State’s ability to stage major offensives and capture new areas, despite a string of recent losses in Syria and Iraq.

American Special Operations forces and a coalition of Syrian and Arab fighters known as the Syria Democratic Forces have begun clearing areas north of Raqqa, the Islamic State’s de facto capital in Syria, in preparation for an eventual assault on the city.