(Repeats story, text unchanged)
* Ruling party evokes spirit of Ataturk after coup bid
* Turks united in opposition to attempted power grab
* Post-coup unity may prove hard to maintain
By Asli Kandemir and Daren Butler
ISTANBUL, Aug 9 (Reuters) - After years of being gradually eclipsed as President Tayyip Erdogan forges a "new Turkey" with Islam firmly at its heart, the secular republic's founder Mustafa Kemal Ataturk has, for now at least, made a comeback in the wake of a failed coup.
At a rally of more than a million people in Istanbul on Sunday, Erdogan drew a parallel between the spirit of the young officer who founded modern Turkey in 1923 and the civilians who took to the streets on July 15 to try to stop rogue soldiers in tanks and helicopters from seizing power.
"The belief that helped war veteran Mustafa Kemal start and win the war of independence was running through all Turkey's cities on July 15," Erdogan told the Istanbul rally, portraits of himself and Ataturk blowing in the breeze on either side of the huge stage.
From a leader bent on raising a "pious generation", it seemed a major gesture of conciliation, an attempt to bridge a deep divide in Turkish society reaching back to 1923, when Ataturk forged the secular republic from the ruins of an Ottoman theocracy and banished Islam from public life.
Since the failed coup, Ataturk's portrait has been hung from the headquarters of the ruling AK Party, founded by Erdogan and rooted in political Islam, and its leaders have repeatedly invoked him - a revered figure for the country's secularists - as a symbol of unity.
Kemal Kilicdaroglu, leader of the main opposition CHP, the party of Ataturk, told Sunday's rally a "door of compromise" had been opened in the nation of almost 80 million and that a new Turkey had been ushered in in the wake of the coup.
But for all the euphoria, sustaining such a spirit of cooperation would mean overcoming deep division over the direction of a nation with a secular constitution but overwhelmingly Muslim population.
"This is a limited consensus. It's a very basic agreement that democracy is better than a military junta and that we all want justice. Nobody expects anyone to forget where they stood on July 14," said a senior government official.
Engin Altay, a senior CHP lawmaker, said the AK Party appeared to be invoking Ataturk to try to quell an atmosphere of "pessimism and panic" after the coup attempt and said it was an open question whether the spirit of unity would last.
"It depends on whether, after emerging from this trauma, the AK Party can adopt a compromise policy without becoming drunk on, or poisoned by, power. If it fails to do so and says 'we got power from the people and will do whatever we say', they will again slam the state against the wall," he told Reuters.
"MARRIAGE OF CONVENIENCE"
Erdogan has cautiously pushed a conservative Islamist agenda since the AKP came to power in 2002. Opponents see in his promotion of religious education, tighter laws on alcohol, and strictures on daily life an attempt to undermine the country's secular foundations.
Ataturk's presence has gradually been felt less, having for decades loomed large, his piercing blue eyes staring from posters, his statue in pride of place in schools, public buildings and town squares. The CHP was in uproar in 2013 over the removal of his silhouette and the Turkish Republic abbreviation from state medals and some public buildings.
But the coup bid, which Erdogan says was staged by the followers of U.S.-based Turkish cleric Fethullah Gulen, has provided a common enemy. Secularists loathe Gulen's religious movement, whose members have assumed prominent positions in the state bureaucracy, and are pleased to see it under attack.
More than 60,000 people in the military, judiciary, civil service and education have been detained, suspended or placed under investigation over alleged links to Gulen since the coup.
The government may be forced as a result to work more with its secularist opponents, commonly known as Kemalists, as it replaces purged officials, particularly in the military, which for decades saw itself as the guardian of the secular order.
"This requires the government to recalibrate its relations with Kemalism ... which it has demonized throughout its 14-year rule," said Gonul Tol, director of the Washington-based Middle East Institute's Center for Turkish Studies.
"The military will have to accept working under an Islamist government while the government will have to respect the Kemalist core of the military," she said. "But I don't think this marriage of convenience will last. Once the government has enough loyal personnel ... the Kemalists will be discarded."
A return to the founding principles of the modern republic could help ease divisions in a country that has become increasingly polarised in recent years. But in Erdogan's references to Ataturk, some see political opportunism rather than a sincere attempt to bridge an ideological rift.
"The switch is the result of strategic necessity rather than personal choice," said Deniz Ulke Aribogan, international relations professor at Istanbul University.
"This brutal coup attempt created an opportunity for Erdogan to become the president of the whole country ... We have to wait and see what comes next," she said.
Erdogan's core supporters see him as the champion of the pious Anatolian masses, a strongman restoring religion to the centre of public life after decades of rule by what they see as Western-facing Kemalist elites.
He has been careful in his choice of words, referring to Ataturk simply as Mustafa Kemal, his name as a military officer when he led the Turkish National Movement to victory in the war of independence after the defeat of the Ottoman Empire.
Ataturk, "Father of the Turks", was bestowed on him a decade later, after he introduced reforms replacing Arabic with Latin script and promoting Western dress and women's rights.
Some in conservative religious circles have already questioned the references to him, criticising what they say legitimises a secularist ideology they battled for decades.
"All they've done is feed the idea that the ideology of Ataturk is the only foundation for legitimacy in politics and that other movements are illegitimate," wrote columnist Hakan Albayrak in the conservative Karar newspaper, criticising those who hung Ataturk's image on the AKP building.
Parts of the crowd booed as Kilicdaroglu spoke at Sunday's rally, dismissing his call that politics should now be kept out of the mosques, as well as the courthouses and barracks.
His presence on the stage alongside Erdogan would have been unthinkable three weeks ago. It could yet cost the CHP some supporters, who remain suspicious of Erdogan's motivation.
"I don't find this situation sincere at all. They can't even say the word Ataturk. For now, it suits them. If it suited them, tomorrow they would start insulting him," said Burcu Ural, a cafe owner in Istanbul's bohemian Beyoglu district. (Additional reporting by Tuvan Gumrukcu; Editing by Nick Tattersall and Peter Graff)
Our Standards: The Thomson Reuters Trust Principles.