Turkey’s prime minister, Ahmet Davutoğlu, has confirmed that the country’s forces have struck Kurdish YPG militia targets in northern Syria, and have demanded the group withdraws from the area it has recently captured.

The shelling took place on Saturday after Kurdish fighters, backed by Russian bombing raids, drove Syrian rebels from a former military air base near the Turkish border.

“We will retaliate against every step [by the YPG],” Davutoğlu told reporters in comments shown live by state broadcaster TRT Haber on Turkish television. “The YPG will immediately withdraw from Azaz and the surrounding area and will not go close to it again.”

A security official said the shelling was retaliation under Turkish military rules of engagement, after the PYD – the Kurdish Democratic Union party, regarded by Ankara as a terrorist organisation – and forces loyal to the Syrian president, Bashar al-Assad, opened fire on Turkish military outposts on the border.

The Syrian Observatory for Human Rights, which monitors the war, said the shelling had targeted the air base and a village captured from insurgents by the PYD-backed YPG militia.

A Kurdish official confirmed the shelling of the Menagh base, which he said had been captured by the Kurdish-allied Jaysh al-Thuwar group rather than the YPG. Both are part of the Syria Democratic Forces alliance.

The shelling came amid growing anger in Ankara with US backing for the PYD in its fight against Islamic State (Isis) militants.

The PYD controls most of the Syrian side of Turkey’s border and Ankara views it as an extension of the Kurdistan Workers Party (PKK), which has waged a three-decade-old insurgency for autonomy in southeast Turkey, and whose bases in Iraq’s Qandil mountains have been bombed repeatedly by the Turkish military.

“When there is any threat to Turkey, we will take in Syria the measures that we took in Iraq and in Qandil and will not hesitate to implement the necessary measures,” Davutoğlu said in a speech in the eastern Turkish city of Erzincan.

Turkey’s disquiet has been heightened by the tens of thousands of people fleeing to its border after attacks by Russian-backed Syrian government forces in Aleppo, swelling refugee numbers in the area to 100,000.

Turkey, which already hosts 2.6 million Syrian refugees, has kept the latest arrivals on the Syrian side of the border, in part to pressure Russia to cease its air support for Syrian government forces near the city of Aleppo.

Davutoğlu condemned the attacks in Aleppo as “barbarity, tyranny, a war strategy conducted with a medieval mentality” and said hundreds of thousands of people in the region faced the danger of starvation if a humanitarian corridor was not opened.

“We will help our brothers in Aleppo with all means at our disposal. We will take those in need but we will never allow Aleppo to be emptied through an ethnic massacre,” he said.

Turkey is a Nato member and is one of Assad’s most vehement critics and an ardent supporter of opposition forces.

The Turkish foreign minister, Mevlüt Çavuşoğlu, was reported as saying on Saturday that Saudi Arabia would send aircraft to Turkey’s Incirlik air base for the fight against Isis.