It’s an unusually hot autumn in the plains of southern Turkey, where in some places nothing but wire fencing is all that separates this country from the chaos that has engulfed Syria over the last eight years.

Cotton, pistachio and olive trees grow on both sides of the border. But plumes of black smoke are only rising above towns on the Syrian side.

From the outside, Turkish president Recep Tayyip Erdogan’s war on the Kurdish-led Syrian Democratic Forces (SDF) appears to be a foreign policy disaster: Ankara is looking at possible sanctions and a European arms embargo, as well as a rising civilian death toll and accusations of war crimes that have led to a surge in international sympathy for Kurdish civilians bearing the brunt of the attack.

At home, however, it’s a winner. Operation Peace Spring is not only the likely fulfilment of an important long-standing national security goal – it has allowed Erdogan to whip up nationalistic sentiment and drive a wedge through his political opposition, whose alliance has fallen apart over the Kurdish issue.

At least 24 people are facing terrorist propaganda charges for social media posts critical of the operation, and new investigations have been launched into members of the pro-Kurdish People’s Democratic Party (HDP), the only political party that has voiced opposition.

But dissent is vanishingly rare in Erdogan’s Turkey, particularly as the almost entirely pro-government media, pop stars and athletes have lined up to praise his leadership and bravery.

As a result, for most Turks, particularly in border towns such as Akçakale that are facing SDF counterattacks, there is no doubt who the enemy is.

“This is all your fault,” one man said, emerging from a four-storey house hit by SDF shelling, visibly shaking with anger. In his hand he clutched a fragment from the mortar shell that killed a nine-month-old Syrian baby on the floor below and put his two older sisters in intensive care. “You westerners, you abandoned your Nato ally Turkey to support the terrorists. And now look what is happening.”

After Syrian president Bashar al-Assad withdrew his troops from the country’s north-east in 2012 to concentrate on fighting rebels elsewhere, the local Kurdish population formed the People’s Protection Units (YPG), a militia designed to protect the semi-autonomous state the Kurds carved out in the regime’s absence.

Facebook Twitter Pinterest Turkish President Recep Tayyip Erdogan poses for a selife during an African Muslim Religious Leaders Summit. Photograph: AP

The move greatly alarmed Turkey, as the YPG is so closely linked to the Kurdistan Workers’ Party (PKK), an insurgency the state has battled for decades in fighting that has killed up to 40,000 people.

After the rise of Islamic State in 2014, the US had a choice of ground partners in the battle: Syria’s Arab rebel opposition, backed by Turkey, by that point tainted by war crimes, and Islamist links – or the YPG. The US chose the YPG, encouraging its leaders to rebrand as the Syrian Democratic Forces (SDF) and bring in Arab, Christian, Turkmen and Yazidi recruits in order to blur its origins.

Turkey, furious, insisted throughout the five-year campaign against Isis that Kurdish cooperation was a Trojan horse that had strengthened an enemy all along its southern border.

Erdogan will use anyone and do anything to hang onto his power. The strategy is cruel

“The policy [of backing the YPG] was not a long-term strategy,” said one former official in Barack Obama’s administration. “We knew it had to be temporary because there was no way Turkey would tolerate that threat.”

As it stands, Erdogan is now set to get exactly what he wants.

Last Sunday the Kurds struck a deal with Assad for military reinforcements to fend off the Turkish attack – a situation tolerable for Ankara, as it will dilute Kurdish control.

A ceasefire agreed with US vice- president Mike Pence and secretary of state Mike Pompeo on Thursday allowed both Washington and Ankara to save face after Donald Trump’s bizarre letter to Erdogan warning him “Don’t be a fool!”, even though the fighting on the border has not halted.

The real deal is likely to be meshed out with Assad’s ally, Russian president Vladimir Putin, during Erdogan’s visit to Sochi on Tuesday. But with all parties apparently negotiating the size of Turkey’s proposed border “safe zone”, rather than whether Turkish troops should leave or not, Erdogan’s attack on the SDF looks set to be a success.

Domestically, too, Erdogan emerges strengthened. The president’s grip on power diminished in March for the first time in his 16 years in charge after voters punished him for Turkey’s burgeoning economic crisis in crucial local elections across the country.

Turkey’s beleaguered opposition managed to wrest control of both the capital Ankara and economic hub Istanbul after the pro-Kurdish HDP gave its unofficial endorsement to the secular People’s Republican Party (CHP), a landmark victory in a country where many fear democracy is failing.

Ekrem Imamoglu, Istanbul’s new mayor, popular for his inclusive and anti-populist stance, surged to a resounding second victory in a re-run of the poll in June and is now touted as a possible presidential candidate in 2023. But he has voiced strong support for Erdogan’s military operation that threatens to scupper the opposition’s new-found solidarity.

“Political parties in Turkey, except HDP, easily unite when it comes to the Kurdish issue... the perception ‘Turkey is under existential threat’ is broadly shared by political actors,” said Sinem Adar, a researcher at the German Institute for International and Security Affairs.

“This undoubtedly has a quite devastating effect on HDP’s trust in the opposition, especially after its support in the local elections. Given that Imamoglu’s landslide victory in the re-run would not have been possible without the support of HDP voters, we can say that the breach of trust will be difficult – if not impossible – to repair.”

The other target of Operation Peace Spring is Turkey’s 3.6m Syrian refugee population. The government’s attitude towards refugees has ebbed and flowed over the years, but after embracing those who now have citizenship as potential conservative AKP voters, this summer Syrians became the definitive scapegoat for Turkey’s economic woes.

Ankara says up to two million Syrians will be resettled in the proposed 20m (32km) deep border safe zone carved out of mainly Kurdish territory, even though most are Arabs originally from other parts of the county – and very few people seem keen to move to a place they have never been.

“We [Syrians] are being used as political tools, yet again,” said a Syrian woman in the Turkish border town of Gaziantep, who spoke on condition of anonymity to protect her family.

“Filling that area with Arabs is demographic engineering that doesn’t take our needs and safety into consideration. My son didn’t go to school for three days last week because his teacher kept telling him ‘It’s time for you to go home.’

“Erdogan will use anyone and do anything to hang onto his power. The strategy is cruel. In this case it is leaving even more Syrians dead… But it works.”