Users across the country found many ways of circumventing the prohibition, which was widely criticised and ridiculed.

Access to Twitter was blocked in Turkey in the run-up to local elections, which Mr Erdogan's ruling Islamist-rooted AK Party won resoundingly.

On Wednesday Twitter's public policy team welcomed the Turkish court ruling, and said "we hope to have Twitter access restored in Turkey soon". The court told Turkey's telecommunication authority (TIB) to act on the ruling.

Analysis

By James ReynoldsBBC News, Istanbul

In theory, the constitutional court's decision to lift Turkey's Twitter ban is an important moment.

A court has overruled the government to assert its own more expansive interpretation of freedom of speech - and the government now has obeyed the decision.

But, in practical terms, the decision is largely a footnote. The two-week Twitter blackout was largely ignored.

This country's Twitter users found their own way of keeping the lights switched on. As soon as the ban was imposed, most here simply changed their computer settings (a process which takes about 10-15 seconds) to get round the block. Traffic to the site even increased in the days after the formal ban.

Prime Minister Erdogan did not appear to be worried about alienating his country's Twitter users. He gets his political support from working-class and socially conservative voters who do not spend their lives online. This off-line base of support gave his AK Party a clear victory in the 30 March local elections.

Following the Twitter ban the government also banned access to YouTube, after a video on the website appeared to reveal top officials discussing how to stage an undercover attack inside Syria. Foreign Minister Ahmet Davutoglu is heard asking about the possibility of sending tanks in.

The recording was posted on YouTube anonymously. Commenting on it later, Mr Davutoglu implied that it was genuine, not a fabrication. He said that "ordinary pawns are used in the wire-tapping... a cyber attack to a meeting where military and security options were being discussed is no different than a military attack".

Previously Mr Erdogan has alleged that such recordings are being fabricated to turn people against him.

President steps in

Mr Erdogan has lashed out at social media, accusing "plotters" of leaking recordings to deliberately undermine him. A US-based Islamic cleric, Fethullah Gulen, has denied allegations that he is involved.

Referring to the security meeting leaked to YouTube last week, he said the person responsible for the leak must be "revealed" because a crime had been committed.

He also said the eavesdropping had taken place "from inside" - implying that it was not the work of a foreign government.

During the leaked recording national intelligence chief Hakan Fidan is heard saying: "I'll send four men from Syria, if that's what it takes. I'll make up a cause of war by ordering a missile attack on Turkey; we can also prepare an attack on Suleyman Shah Tomb if necessary."

Then the military's deputy chief of staff, Yasar Guler, says "what we're going to do is a direct cause of war".

Further on Mr Davutoglu is heard asking "if the Turkish tanks go in there, it means we're in there in any case, right?" Mr Guler replied: "It means we're in, yes."

Mr Erdogan ordered the Twitter ban after recordings of corruption allegations linked to him and members of his family were posted and shared online. He said the recordings were fake and edited.

During big anti-government demonstrations last year protesters made heavy use of both Twitter and Facebook to spread information.