The appeals court annulled the congress over irregularities and ruled that former Republican People's Party (CHP) chairman Kemal Kilicdaroglu - a divisive figure within the party who lost to Erdogan in an election earlier in 2023 - should replace his successor Ozel.
The case, brought by a former party member, has weighed on the party for years.
It is centred on allegations that delegates were bribed to vote for Ozel during the CHP leadership contest in November 2023.
The case was seen as a test of Turkey's shaky balance between democracy and autocracy, and the ruling may throw the opposition into further disarray and possible infighting.
It could also boost Erdogan's chances of extending his more than two-decade rule of the big NATO military alliance member country and major emerging market economy.
The CHP rejected the ruling as an "attempted coup" while the government - which denies criticism that it uses courts to target political opponents - said it renewed Turks' faith in the rule of law.
The secular and centrist CHP, running roughly even with Erdogan's Islamic-rooted and conservative ruling AK Party in polls, has also faced an unprecedented judicial crackdown since 2024 in which hundreds of members and elected officials have been detained as part of corruption charges that the party denies.
Among those imprisoned for more than a year is Istanbul mayor Ekrem Imamoglu, who is Erdogan's main rival and the CHP's official candidate for a presidential election set for 2028 but that could come next year.
Ozel - the CHP's combative chair - who has risen to prominence since Imamoglu's arrest, convened party leaders to discuss a response to the court ruling while protests were planned.
Ali Mahir Basarir, CHP deputy parliamentary group chair, told Reuters the ruling "is an attempted coup carried out through the judiciary (and) a blow against the will of 86 million people".
Those behind it "will be held accountable before the courts," he said.
Turkey's main Borsa Istanbul dropped six per cent in response, triggering a market-wide circuit breaker, while government bonds slid.
The central bank sold billions of US dollars in forex to ease the fallout, four traders said.
In March last year, Imamoglu's detention sparked a sell-off that sent inflation expectations higher and temporarily reversed a rate-cutting cycle.
Investors said the latest political turmoil would be watched for similar risks.
The ruling by the Ankara court overturned a decision last year by a court of first instance that said the case surrounding the CHP's 2023 congress had no substance.
The pro-Kurdish DEM Party, parliament's third-largest, called the court decision a "black stain" on Turkish democracy.
The reinstated CHP leader Kilicdaroglu, who had largely faded from public view since his electoral defeat three years ago, called for calm and common sense and said he hoped Turkey would benefit from it.
with DPA