Hundreds of thousands of people joined a rally in Istanbul at the end of a 25-day “march for justice” against the government of the Turkish President, Recep Tayyip Erdogan.

The opposition Republican People’s Party leader, Kemal Kilicdaroglu, led the 280-mile walk from Ankara to Istanbul after his deputy leader was imprisoned in June.

Mr Erdogan has spearheaded a large-scale government crackdown against opponents in the wake of a failed coup against him last summer, and was granted sweeping new powers following a controversial referendum in April.

“If only there was no need for this march and there was democracy, media freedoms, if civic society groups could freely express their opinions,” Mr Kilicdaroglu said.

The opposition leader was once seen as weak but has emerged as the voice of many Turks, even prompting comparisons to Mahatma Gandhi, who led peaceful protests against British rule in India.

Kemal Kilicdaroglu, leader of main opposition Republican People's Party, speaks during a rally to mark the end of his 25-day long protest, dubbed 'Justice March', against the detention of the party's lawmaker Enis Berberoglu in Istanbul (Umit Bektas/Reuters)

Mr Kilicdaroglu told Reuters his three-week march had helped Turks “cast off a shirt of fear” since emergency rule was imposed after the coup attempt.

The 68-year-old attracted relatively modest support in the early stages of his march, but numbers swelled in the final days, with hundreds of thousands carrying banners and the Turkish flag as they demanded “rights, law, justice”.

The government has accused Mr Kilicdaroglu of supporting terrorist groups with his protest and violating the law by attempting to influence the judiciary.

Mr Erdogan claims to be cracking down against those who support militant organisations, but the government definition of what constitutes backing terrorism is so broad it has led to the arrest of thousands of civil servants, journalists, campaigners and other workers.

Turkey's President Recep Tayyip Erdogan talks to media (REUTERS)

Parliamentarian Enis Berberoglu was sentenced last month to 25 years in prison for revealing state secrets after he allegedly leaked documents to an opposition newspaper suggesting the Turkish government had armed jihadists in Syria. A journalist by profession, the opposition party's deputy leader has long been a thorn in Mr Erdogan's side.

In a New York Times article on Friday, Mr Kilicdaroglu called the case against Mr Berberoglu “the last straw in a series of anti-democratic moves” by the government “targeting tens of thousands of Turkish citizens - politicians, journalists, academics, activists or ordinary citizens”.

After last year's aborted coup, the government imposed a state of emergency leading to the arrest of more than 50,000 people and the dismissal of 100,000 civil servants. A dozen legislators from a pro-Kurdish opposition party have also been jailed.

In pictures: Turkey coup attempt Show all 17 1 /17 In pictures: Turkey coup attempt In pictures: Turkey coup attempt Turkish President Erdogan attends the funeral service for victims of the thwarted coup in Istanbul at Fatih mosque on July 17, 2016 in Istanbul, Turkey Burak Kara/Getty Images In pictures: Turkey coup attempt Soldiers involved in the coup attempt surrender on Bosphorus bridge with their hands raised in Istanbul on 16 July, 2016 Gokhan Tan/Getty In pictures: Turkey coup attempt A civilian beats a soldier after troops involved in the coup surrendered on the Bosphorus Bridge in Istanbul, Turkey, 16 July, 2016 REUTERS/Murad Sezer In pictures: Turkey coup attempt Surrendered Turkish soldiers who were involved in the coup are beaten by a civilian Reuters In pictures: Turkey coup attempt Soliders involved in the coup attempt surrender on Bosphorus bridge Getty In pictures: Turkey coup attempt Supporters of Turkish President Recep Tayyip Erdogan wave flags as they capture a Turkish Army vehicle Getty In pictures: Turkey coup attempt People pose near a tank after troops involved in the coup surrendered on the Bosphorus Bridge in Istanbul, Turkey, 16 July, 2016 Reuters In pictures: Turkey coup attempt Turkish soldiers block Istanbul's Bosphorus Brigde Getty In pictures: Turkey coup attempt A Turkish military stands guard near the Taksim Square in Istanbul Reuters In pictures: Turkey coup attempt Pierre Crom/Twitter In pictures: Turkey coup attempt Turkish soldiers secure the area as supporters of Recep Tayyip Erdogan protest in Istanbul's Taksim square AP In pictures: Turkey coup attempt People demonstrate in front of the Republic Monument at the Taksim Square in Istanbul Murad Sezer/Reuters In pictures: Turkey coup attempt Turkish soldiers detain police officers during a security shutdown of the Bosphorus Bridge Reuters In pictures: Turkey coup attempt Turkish Army armoured personnel carriers in the main streets of Istanbul Getty In pictures: Turkey coup attempt Chaos reigned in Istanbul as tanks drove through the streets EPA/TOLGA BOZOGLU In pictures: Turkey coup attempt Turkish President Tayyip Erdogan speaks to media in the resort town of Marmaris Reuters In pictures: Turkey coup attempt Supporters of President Erdogan celebrate in Ankara following the suppression of the attempted coup Reuters

Among the marchers were ordinary citizens, sacked public employees and several high-profile figures, including novelist Asli Erdogan and leading Kurdish politician Ahmet Turk, both released from prison pending trial on various terror-related charges, and Yonca Sik, the wife of a prominent journalist currently in jail.

The detention of human rights activists and leading journalists has drawn international condemnation and damaged the country’s bid to join the European Union.

Organisers said the protest expressed “a collective, non-partisan desire for an independent and fair judicial system”. No party flags or slogans were allowed on the march.