The central bank said deterioration in pricing behaviour continued to pose upside risks on the inflation outlook, despite weaker domestic demand conditions.
The bank described the hike as a "strong monetary tightening to support price stability".
The currency has lost 40 percent of its value against the dollar this year, hit by concerns about Erdogan's influence on monetary policy and more recently by a diplomatic spat between Turkey and the US.
Brett Diment at Aberdeen Standard Investments said raising rates would put "Turkey on the slow road to recovering some monetary policy credibility, and that is critical".
The main share index rose 2.1 per cent, with the banking index up 4.8 per cent. Dollar-denominated bonds issued by the Turkish government rose across the curve.
Its monetary committee made a decision to "implement strong monetary tightening to support price stability", it said on Thursday, as it raised interest rates by 625 basis points in the face of a spike in inflation and a slump in the lira.
Key rates are now at their highest level since 2004, around a year after Erdogan first came to power. "A rate hike would be an important step to restore market confidence in the lira".
Rising U.S. interest rates have discouraged the riskier reach for yield, deepening home-grown crises. The rate hike could squeeze growth further, but independent experts say it is needed to contain inflation of about 18% and support the currency.
It has now increased interest rates by 11.25 percentage points since late April as it struggles to bring the lira out of freefall.
It was not immediately clear if Erdogan had been aware of the central bank's decision when he made his comments.
"It was a big surprise to us, but probably to every Turkey-watcher", said Nora Neuteboom, an economist at ABN Amro, saying the move was a "positive signal" with the bank wanting to show its independence and commitment to fight inflation.
Piotr Matys at Rabobank said Turkey also needed to resolve its trade dispute with the United States and rebalance the economy away from big infrastructure projects and consumer spending.
The bank said on Thursday that inflation developments pointed "to significant risks to price stability" due to the recent fall in value of the lira.
Mr Erdogan has previously urged Turks to sell their dollars and euros.
In another bid to prop up the lira, Erdogan earlier on Thursday ordered by decree that property agreements in foreign currencies would not be allowed.
Donald Trump Attacks Nike As New Controversial Ad Is Revealed
Tiger Woods endorsed Nike's latest "Just Do It" ad narrated by Colin Kaepernick with a message almost as succinct. But I think as far as sending a message, I think it's a awful message and a message that shouldn't be sent.