Republican People's Party leader Kemal Kilicdaroglu launched the 450-kilometer (280-mile) march after a parliamentarian from his party was imprisoned in June. The march grew into a protest of the massive clampdown on people with alleged links to terror groups that began after a coup attempt last summer.
"Why did we march?" Kilicdaroglu said while addressing the rally. "We walked for the non-existent justice. We walked for the rights of the oppressed, for the imprisoned lawmakers, the jailed journalists... We walked for the academics who were thrown out of universities."
Once seen as feeble in his role as opposition leader, Kilicdaroglu has emerged as the voice of many Turks and been likened to India's Mahatma Gandhi, who led a nonviolent march against British colonial practices.
Tens of thousands of people joined Kilicdaroglu throughout his march in scorching heat, chanting "rights, law, justice." Hundreds of thousands greeted him at the Istanbul rally, while waving Turkish flags and flags emblazoned with the word "justice."
"No one should think the end of this march is the end. This march was our first step," Kilicdaroglu said. "July 9 is a new step. July 9 is a new climate. July 9 is a new history."
The opposition leader called on judges and prosecutors to act independently and according to their "conscience" instead of in line with the wishes of "the palace" -- a reference to President Recep Tayyip Erdogan.
He also called for an end to a state of emergency that was declared following the failed coup and which has allowed the government to rule by decrees, with minimal input from parliament.
"We want the state of emergency to be removed and for Turkey to normalize," Kilicdaroglu said. "We want politics kept out of the judiciary, the (army) barracks and of mosques. We want a neutral and independent justice. We want a Turkey where journalists are not jailed."
Organizers said the weekslong event expressed "a collective, nonpartisan desire for an independent and fair judicial system" that they claim is lacking in Turkey. The Republican People's Party did not allow party flags or slogans during the march because it wanted the event to be non-partisan.
Party officials said more than a million people attended the closing rally.
"There is no justice," Muhammer Dogan, 64, who joined the rally, said. "Innocent people are being imprisoned. They are being victimized."
The government has accused Kilicdaroglu of supporting terrorist groups through his protest. President Recep Tayyip Erdogan has said he is violating the law by attempting to influence the judiciary.
Turkey's definition of supporting terror is so broad that it has caused an impasse in the country's bid for European Union membership.
US Secretary of State Rex Tillerson also arrived in Istanbul on Sunday to accept an oil industry award and to meet with Turkey's foreign minister and Erdogan.
Parliament member Enis Berberoglu was sentenced last month to 25 years in prison for revealing state secrets for allegedly leaking footage to an opposition newspaper suggesting that Turkey's intelligence service had smuggled weapons to Islamist rebels in Syria.
The state of emergency has led to the arrest of more than 50,000 people and the dismissal of some 100,000 civil servants. A dozen lawmakers from the pro-Kurdish opposition party have also been jailed.
Ordinary citizens, sacked public employees and high-profile figures have joined Kilicdaroglu on his march. Novelist Asli Erdogan and leading Kurdish politician Ahmet Turk, both released from jail pending trial on various terror-related charges, as well as Yonca Sik, the wife of a prominent journalist currently in prison, were just a few.
Istanbul governor Vasip Sahin said 15,000 police officers were providing security at the post-march rally.