Ankara considers the Kurdish People's Protection Units (YPG) fighting in Syria to be a terrorist group and the Syrian branch of the outlawed Kurdistan Workers' Party (PKK), which has waged an insurgency against

"We will not hesitate to use our legitimate right to defence against formations that threaten our country's security."

"We will never remain silent or unresponsive to the backing and arming of terrorist groups, and the formation of terror islets right next to our border," Erdogan said in a speech at the closing session of the G20 summit in Hamburg.

President Recep Tayyip Erdogan on Saturday said Turkey would never allow a Kurdish state in Syria near its border, and warned that if threatened, Ankara would not hesitate to use its right to self-defence.

Sign up for our Newsletter

But the United States sees the YPG as the most effective group on the ground in the fight against Islamic State jihadists, and is openly arming the militia force to the dismay of its NATO ally.

Ankara fears the creation of a Kurdish state in northern Syria could encourage separatism amongst its own Kurds.

Erdogan said Turkey would "never allow" a Kurdish state in northern Syria.

Turkish troops and YPG forces have repeatedly exchanged cross-border fire in recent days, and there is speculation Ankara may be planning an assault on the group in the northern Syrian town of Afrin.

Tens of thousands of people protested against Turkey in Afrin on Wednesday, chanting: "No to Turkish intervention."

Erdogan said the issue of Afrin was a "threat" for Turkey.

"As long as this threat continues, we will activate our rules of engagement and will continue to give the necessary answer to those in Afrin," he said.

The Turkish leader also hit back at the Iraqi Kurdistan region's plan to hold a referendum on independence.

"It is a troubling step for Iraq's future," he said in Hamburg.

He said Turkish concerns were conveyed to Iraqi Kurdish leader Messud Barzani, an ally of Ankara.

"We said 'this is a wrong path. Give up on this, otherwise it will be difficult for you to pay a price tomorrow.' I don’t know at what stage they are right now," Erdogan said.

"I hope that they will give up holding a referendum."