ANKARA (Reuters) - Turkish and Syrian heads of intelligence met in Moscow on Monday, in the first official contact in years despite Ankara’s long-standing hostility to President Bashar al-Assad, a senior Turkish official and Syrian news agency SANA said.

Both sides have said there have been intelligence contacts, but this is the first explicit acknowledgement of such a senior meeting.

Turkish President Tayyip Erdogan backs rebels who fought to topple Assad during Syria’s eight-year civil war. Erdogan described Assad as a terrorist and called for him to be driven from power, which earlier in the war had appeared possible.

But Assad’s allies Russia and Iran helped turn the conflict round, and with U.S. forces now withdrawing from northeast Syria, Assad’s Russian-backed troops are sweeping back into the region just as Turkish troops move in from the north.

Turkey’s intelligence chief, Hakan Fidan, and his Syrian counterpart discussed the ceasefire in Syria’s Idlib, and possible coordination against the Kurdish presence in northern Syria.

The discussions included “the possibility of working together against YPG, the terrorist organisation PKK’s Syrian component, in the East of the Euphrates river,” a Turkish official said, speaking on condition of anonymity.

SANA news agency said Syria’s intelligence chief called on Turkey to fully adhere to the sovereignty of Syria, its independence and territorial integrity as well as the immediate and full withdrawal from the whole Syrian territory.

Last year, Turkey and Russia signed a deal, dubbed the Sochi agreement, under which Syrian and Russian forces deployed in northeast Syria to remove Kurdish YPG fighters and their weapons from the border with Turkey under a deal, which both Moscow and Ankara hailed as a triumph.

Despite backing opposing sides in Syria’s conflict, Ankara and Moscow have grown closer, their ties strengthened by joint energy projects and Turkey’s purchase of Russian air defences - to the anger of its NATO ally the United States.

Turkey and Russia have cooperated more closely on Syria since agreeing two years ago to work along with Assad’s other main ally, Iran, to contain the fighting.