By Nick Tattersall and Humeyra Pamuk
ISTANBUL (Reuters) - The recapture of Aleppo by Syrian government forces deals a humiliating blow to years of Turkish policy in Syria, leaving in ruins its efforts to force President Bashar al-Assad from power and handing a major victory to main regional rival Iran.
But Turkey's support for the Syrian rebels withdrawing from their last major urban stronghold is far from over, as it intensifies a campaign to drive Islamic State and Kurdish militia fighters from a strip of Syria's north.
Some of the rebel brigades from Aleppo are expected to be redeployed as part of "Operation Euphrates Shield", an offensive launched by Turkey four months ago to secure a roughly 90-km (56-mile) stretch of Syrian territory across its border.
"The work on this is already under way," said a senior official from the Turkmen Sultan Murad brigade, one of the Turkish-backed groups pulling out of Aleppo. Fighters would initially join Turkey's effort to drive Islamic State from the city of al-Bab, around 40 km northeast of Aleppo, he said.
Turkish President Tayyip Erdogan's role negotiating the safe exit from Aleppo of the largely Turkmen and Arab insurgents he has backed for the past five years was hardly the outcome he could have wanted. For years, he led calls for international intervention to force Assad from power.
But it marks the culmination of a shift in Turkish policy which began months ago as Ankara sought to mend broken ties with Assad's ally Russia, and as the threat to its national security from Islamic State and Kurdish groups in Syria grew.
Turkey itself pulled some of the rebel fighters it backs out of Aleppo in August to take part in Euphrates Shield, further weakening their ability to confront the onslaught from Assad's forces and their Russian and Iranian-backed allies.
"The situation in Syria has morphed into one reality and then another since 2011 and all regional actors ... have muddled through, trying to adjust to new realities. In this respect, Turkey is no exception," said Gulnur Aybet, professor of international relations at Istanbul's Bahcesehir University.
"Turkey's priorities with regards to the war in Syria now and for the foreseeable future are two pronged: national security and humanitarian relief."
"TERRORIST TRAINING GROUND"
A chain of suicide bombings over the past two years blamed variously on Islamic State and Kurdish militants have brought into sharp focus the threat from Syria to Turkish cities hundreds of miles from the frontlines.
"Syria has turned into a training ground for terrorist organizations," a senior government official said. "Our Syria policy is adjusting according to the realities on the ground."
In the latest attack last weekend, Kurdish militants claimed a twin bombing outside an Istanbul soccer stadium which killed 44 people, most of them police officers.
Foreign Minister Mevlut Cavusoglu said on Wednesday one of the bombers was thought to have come from Syria, and officials in Ankara believe the attacks may have been in revenge for Turkey's actions against Kurdish militias in northern Syria.
"They are not pleased with the advances of the Turkish army in Syria, and they're trying to send a message to Turkey through terrorist attacks," said a second Turkish official.
"Our fight against terror in Turkey and the Turkish-backed rebel advance in Syria will continue."
The official from the Sultan Murad brigade said rebel fighters withdrawing from Aleppo to Syria's Idlib province would be vetted by Turkey before being sent to join the Euphrates Shield operation as quickly as possible.
Speaking on condition of anonymity, he said the aim was to flush out members of the Nusra Front, which is among the rebel groups fighting Assad but was until recently affiliated with al Qaeda. The Nusra Front is considered a terrorist group by both the United States and its NATO ally Turkey.
"It won't take a lot of time, definitely not weeks. The al-Bab operation is vital for Turkey, and from there it wants to move onto Manbij," the Sultan Murad official said, referring to a town 50 km (30 miles) east of al-Bab which Erdogan has said he wants brought under control of the Turkish-backed forces.
The Turkish army dropped leaflets on al-Bab this week urging civilians to seek shelter, as rebels backed by Turkish tanks and warplanes closed in on the city. The rebels seized at least two villages west of al-Bab last week.
Turkey's shifting priorities in Syria have much to do with its rapprochement with Russia in August, after nine months of strained ties caused by Turkey's shooting down of a Russian fighter jet over Syria.
Russia has backed up forces loyal to Assad in Aleppo by providing training, equipment, advice and air support.
The Turkish government says the restoration in ties has not changed its position that Assad must go to restore peace in Syria, but it has been forced to work with Moscow. Erdogan has spoken repeatedly in recent weeks with Russian President Vladimir Putin to try to find a solution in Aleppo.
There have also been contacts between Turkey's foreign minister and his Iranian counterpart in recent days, and Turkish officials have said there will be a tri-partite meeting between Turkey, Russia and Iran to discuss Syria later this month.
Ankara's change of tack has partly been driven by its long-standing frustration with U.S. policy in Syria.
Turkey has been angered by U.S. support for Kurdish militia groups and has shared a sense of betrayal among Syrian rebels who feel President Barack Obama encouraged their uprising by calling for Assad to go but then abandoned them, failing even to enforce his own "red line" on Syria's use of chemical weapons.
"The fight that should have been taken on by global powers has not been assumed by them at all," the senior government official said. "If someone is looking for a scapegoat for what's happening in Syria, it is neither Erdogan nor Turkey."
(Additional reporting by Orhan Coskun; Writing by Nick Tattersall, editing by Peter Millership)