The Constitutional Court unanimously ruled that the ban was a breach of free speech safeguarded by the constitution, sending a statement both to the country's telecommunications authority and the communications ministry to "do what's necessary", Turkish television reported.
The government blocked Twitter on March 20 after the social media site was used to spread audio recordings that allegedly implicated Erdogan and his inner circle in a corruption scandal.
Shutting down the site ahead of crucial March 30 local elections sparked condemnation at home and abroad and earned Turkey a strong rebuke from rights groups and its Western allies.
The court case was brought by academics Yaman Akdeniz of Bilgi University in Istanbul and Kerem Altiparmak of Ankara University, as well as opposition Republican People's Party (CHP) lawmaker Sezgin Tanrikulu.
Also Read
Tanrikulu called the decision "a turning point of the public opposition".
"If (we) want, we can succeed," he tweeted.
Akdeniz, a professor of cyberlaw, used Twitter to attach a copy of the court verdict, which found the ban "violated Article 26 of the Constitution safeguarding freedom of expression".
The ruling follows another by an Ankara administrative court last month that also found the Twitter ban restricted freedom of expression, after the Turkish Bar Association launched a legal challenge.
The government appealed that verdict, and the ban remained in place.
Experts say the latest verdict could set a precedent for future cases and, if respected, could deter the government from imposing further blanket bans on social media, frequently used by Turkey's youth amid claims of government pressure on the mainstream media.