BEIRUT — Kurdish fighters in Syria said Tuesday that militias aligned with President Bashar al-Assad’s government had entered the northern enclave of Afrin in a move that could thwart a Turkish offensive there — or draw Turkey and Syria into direct confrontation.

The announcement followed weeks-long negotiations between Kurdish and Syrian government representatives over the future of the Afrin district. Those talks proceeded as Turkish troops and thousands of their Syrian rebel allies advanced through the surrounding mountains.

Nouri Mahmoud, a spokesman for the Kurdish group, known as the People’s Protection Units, or YPG, said Tuesday that the Syrian government had “responded to the call of duty” by sending military units “to be deployed along the borders and to be involved in defending the unity of Syrian territory.”

But whether the Turkish and Syrian militaries will come into direct conflict for the first time during Syria’s seven-year war remained to be seen. 

The pro-Assad fighters arriving in the enclave Tuesday appeared to belong to Iranian-backed units that have often bolstered the efforts of the Syrian military, and it was unclear whether or when the Syrian army itself would be deployed in the area.

Turkey’s state-run Anadolu news agency reported Tuesday that Turkish shelling had forced the incoming troops to retreat six miles from the city of Afrin. The news agency described the strikes as “warning shots.”

Ankara has framed its offensive in northern Syria as a matter of urgent national security, viewing Kurdish fighters on the Syrian side of the border as an extension of a group of Turkey-based militants that it has fought for decades.

But the fight has presented a challenge for Washington. Although it supports Turkey as a NATO ally, the United States has also championed Syrian Kurdish fighters in the war against Islamic State militants, raising the prospect of clashes between Kurdish fighters and Turkish troops with American soldiers trapped in the middle.

Turkish President Recep Tayyip Erdogan suggested Tuesday that the incoming fighters were acting without the authority of the Syrian government. Speaking at news conference, he warned that Turkey would not allow “a wrongful step” in the future, adding that those who do “would pay a high price.”

Turkish Foreign Minister Mevlut Cavusoglu had signaled Monday that Turkey would consider going on the offensive against Syrian troops. “If the regime is going to clean the PKK/YPG, then there is no problem,” he said, referring to both the ­Turkish and the Syrian groups of Kurds. “If the regime is going into Afrin to protect the YPG, then nothing can stop the Turkish armed forces.”

The developments in Afrin came amid an escalation of ­Syria’s civil war as international powers, including the United States and Russia, scramble to consolidate control of the areas where they wield influence.

Around Damascus, the Syrian capital, Syrian government forces launched one of the bloodiest assaults of the war, killing scores of civilians in the rebel-controlled suburb of Eastern ­Ghouta and pouring hundreds more casualties into a network of opposition-controlled hospitals, which have been pushed to the breaking point.

Dozens of civilians also have been killed in the Turkish offensive, according to the Kurdish-controlled Afrin health ministry. Videos posted on social media have suggested that the Turkish-backed rebels are increasingly responsible for abuses, smashing homes and shops belonging to Kurdish residents and mutilating the bodies of fighters they kill.

For Syrians displaced from other regions affected by the war, the Afrin enclave had long been seen as a haven.

According to the United Nations, tens of thousands of the enclave’s residents have fled fighting elsewhere in Syria. The United Nations reported last week that both Kurdish and Syrian authorities have prevented civilians from fleeing, unless they are acutely wounded or ill. In interviews with The Washington Post, families said they have paid as much as $500 to escape the area along smuggling routes.

“People here will support any deal that will stop the killing of civilians and the Turkish shelling. I’m watching those vehicles heading to Afrin, and we just want any solution that will save people’s lives,” said Jovin Hagee, an English teacher in Afrin.

“In the end, war is terrible and civilians will always be the biggest losers from this Turkish offensive.”