Turkish President Recep Tayyip Erdogan (C) waves to his supporters in front of his residence after a failed coup attempt, in Istanbul, Turkey, 16 July 2016.

President Recep Tayyip Erdogan has been repeatedly returned to office in elections generally seen as fair, but he has had to battle enemies on many fronts to maintain and consolidate his grip on power.

Even adversaries who seemed defeated or contained have come back to strike again. Whether with the military, the Kurdish minority or social media, Erdogan has fought some battles multiple times.

Erdogan has said the coup attempt was a "blessing from God" to enable him to clean his enemies out of the state.

Fethullah Gulen: Currently, enemy number one.

The Turkish-born US-based Islamic preacher was once an ally of Erdogan. His followers filled the ranks of the civil service in Turkey, especially the judiciary and law enforcement. The two men worked together to weaken the old military elite's control within the state.

However, in recent years a schism emerged for reasons that were never made public.

In 2013, a wide-ranging corruption investigation was opened against top officials, threatening the stability of the government. Erdogan, blaming the Gulenists for launching the probe, cracked down, purging many thousands from the police and judiciary.

Since then, not a week goes by without the announcement of numerous arrests of alleged Gulenists from the "parallel state." The government claims - without proof - that this group's "fingerprints" are all over the coup attempt.

The military:

Erdogan worked with the Gulenists to weaken the power of the military, which has unseated four governments, amid signs that leftovers from the generals' so-called deep state had machinations to control the country.

In 2007, an investigation was officially opened into Ergenekon, an alleged clandestine secularist, nationalist and military-oriented organization. Hundreds were arrested in the following years, from generals to journalists, accused of trying to foment unrest and potentially unseat the government.

Ultimately, nearly all those accused of involvement were released and the evidence against them found to be doctored.

Social media:

When the coup attempt was under way, Erdogan used Facetime - a phone application - to call into television stations and urge his supporters to take to the streets. It was a noteworthy move by a president who has repeatedly expressed his disdain for social media.

In 2014, after alleged Gulenists released wiretapped phone conversations purporting to show corruption within the government, Twitter and YouTube were banned, as Erdogan threatened to "wipe out" such platforms. But users found workarounds and ultimately the bans were lifted.

After terrorist attacks - increasingly common in recent months - the government throttles social media sites.

The Kurds:

The 1980 military coup had disastrous consequences for the country with a wide-ranging crackdown. Among the victims was the Kurdish language, which was banned for a number of years.

In 1984, the Kurdistan Workers' Party (PKK) emerged as an armed guerilla movement. The group has in recent years moderated its approach, focused now on autonomy rather than separatism.

In 2013, Erdogan and the PKK reached a ceasefire and peace talks were undertaken. In 2015, government ministers and Kurdish leaders outlined the so-called Dolmabahce Agreement, a road map to take the process forward. Erdogan, for reasons unclear, rejected the deal.

In June that year, the pro-Kurdish Peoples' Democratic Party (HDP) was elected to parliament for the first time, seen as a step towards political inclusion, but also denying Erdogan's ruling Justice and Development Party (AKP) a majority.

In July, a suicide bombing targeted a pro-Kurdish group, and the PKK killed two police officers, alleging - without proof - that the policemen were involved. A fresh cycle of violence has since dominated the country, in part being fought by some of the generals accused of involvement in the coup attempt.

Erdogan has also marked the HDP as an enemy.

Islamic State:

Since 2015, Islamic State has targeted Turkey on a number of occasions with suicide bombings and rocket attacks from Syria. Critics say the government did not take the threat from the group seriously enough at first, as it was focused on trying to overthrow Syrian President Bashar al-Assad and worried about Kurdish gains in northern Syria.

Latest news

Trump administration reverses transgender bathroom protections

The Trump administration on Wednesday withdrew Obama-era guidance about the use of school and university bathrooms by transgender students, local media reported.

Several Dakota Access Pipeline protesters arrested as deadline passes

Several people at a camp protesting against a controversial oil pipeline in the US state of North Dakota were arrested Wednesday after a deadline to vacate the land passed, local media reported.

Germany deports 18 rejected asylum seekers to Afghanistan

A Kabul-bound plane with 18 Afghan migrants on board took off from Munich Airport late Wednesday, its passengers becoming the third group of rejected asylum seekers to be deported by German authorities back to Afghanistan.

New Romanian justice minister named after anti-corruption protests

Romanian Prime Minister Sorin Grindeanu has named a former judge to be the country's next justice minister, after the previous office holder resigned under pressure from mass anti-corruption protests.

Le Pen's chief of staff indicted in European Parliament jobs probe

The chief of staff of Marine Le Pen, the far-right candidate for president in upcoming French elections, was indicted Wednesday over allegations of irregular reimbursements from the European Parliament, a judicial source told dpa.

Montenegrin police extradites Miodrag Jovic to Croatia

Montenegrin police reported on Wednesday that they extradited to Croatia Miodrag Jovic (48) from Glina, after whom Interpol Zagreb issued an arrest warrant.

Croatian minister attends CoMoCoSEE conference in Albania

Culture Minister Nina Obuljen Korzinek participated in a third conference of the Council of Ministers of Culture of South-Eastern Europe (CoMoCoSEE) that took place in Tirana on February 21-22.

New Somali president asks al-Shabaab to surrender to 'help' country

Somalia's newly elected President Mohamed Abdullahi Farmajo asked Islamist terrorist group al-Shabaab to surrender in order "to help rebuild" the conflict-ridden East African nation.

Serbia's EU negotiator says minority rights neglected

The head of the Serbia's European Union accession negotiation team, Tanja Miscevic, said in Novi Sad on Wednesday that minority rights had been neglected for many years and added that positive results in that regard cannot be achieved over night, the Beta news agency has reported. 

Scientists: Nearby star's 7 rocky planets are "best bet" for life

New analysis of telescope data shows a dwarf star just 40 light years from Earth has at least seven apparently rocky planets with potential to harbour water, an international team of scientists announced Wednesday.

Croatian PM receives EIB Vice-President

Prime Minister Andrej Plenkovic met on Wednesday with European Investment Bank (EIB) Vice-President Dario Scannapieco for talks on the bank's contribution to a new investment cycle in Croatia and its support to the Croatian government to implement key projects, a press release from the government's office said.

Bomb explodes outside police officer's home in Northern Ireland

A bomb exploded outside a police officer's home in Northern Ireland on Wednesday but there were no immediate reports of casualties.