The original sit-in at Gezi Park spiralled into nationwide unrest after police cracked down on activists defending the green space near Istanbul's Taksim Square from developers.

For days, demonstrators in Istanbul, Ankara and other cities have been calling for the three-term prime minister to quit.

His ruling Justice and Development Party has governed Turkey since 2002, winning a series of election victories.

They accuse his government of becoming increasingly authoritarian and trying to impose conservative Islamic values on a secular state.

Four people including a police officer are reported to have died, thousands have been injured and hundreds arrested in the unrest.

The foreigners detained on Thursday were from France, Germany, Greece, Iran and the US, Turkish Interior Minister Muammer Guler said.

Media playback is unsupported on your device

Media captionHow the crisis spiralled - in 90 seconds

At the scene

By James ReynoldsGezi Park

Inside Gezi Park, Recep Tayyip Erdogan's comments barely generated a reaction. This afternoon many lazed in their tents, picked up litter, or had picnics in the sun. Vendors at makeshift stands sold kebabs and slices of watermelon.

Protesters believe that the prime minister has not listened to them, nor has he given any ground. They want him to abandon plans to develop the park and next-door Taksim Square.

"As long as he continues like this, we will continue," says Levent Yilmaz, a craftsman.

"At least 1,000 people come here every evening. If they want to get rid of us, they will have to use a lot of tear gas. We're not looking for a war - we're here to protect nature and our rights."

Zeynep Seviyilmaz, an actress, says she and her peers are "the youth of this nation".

"Our generation is being challenged - just as our parents were," she says.

'Implicated in terrorism'

Speaking in Tunis, Mr Erdogan acknowledged that police had used "excessive force" against activists at the original sit-in. But he said that a small group of extremists was now manipulating what had started as an environmental protest.

"Among the protesters, there are extremists, some of them implicated in terrorism," he told reporters.

Mr Erdogan also defended the urban development plan for Gezi Park.

"The project respects [Turkey's] history, culture and environment," he said. "What we are doing is to protect the rights of the majority and to preserve the beauty of Istanbul."

Tunisian riot police surrounded the Turkish embassy in Tunis during Mr Erdogan's visit, after local left-wing groups called for protests to show solidarity with the demonstrators in Turkey, the AP news agency reports.

Meanwhile several of Turkey's largest unions called for calm on Thursday.

"Violence and fighting don't solve anything, and they make it impossible to solve problems," the unions said in a joint statement.

In Istanbul, thousands of striking workers joined the demonstrations on Wednesday. They held banners addressed to Mr Erdogan reading: "This nation will not bow to you!" and "Taksim Square is everywhere!"

In the coastal city of Izmir, police have released about 30 people detained earlier for posting "misinformation" on Twitter, the state-run Anatolia news agency reports.

Gezi Park

The demolition of Gezi Park - the issue which sparked the protests - is a part of a wider urban redevelopment project in Istanbul

The government wants to pedestrianise and ease traffic around Taksim Square; Kalyon Group, a company which has close ties with the government, has been contracted to carry out the project

The project also includes building a shopping centre which PM Erdogan says would not be "a traditional mall", but rather would include cultural centres, an opera house and a mosque

The plan also includes rebuilding an Ottoman-era military barracks near the site and demolishing the historic Ataturk Cultural Centre

Some see this as having historic symbolism, as the barracks were the cradle of a pro-Islamic, pro-Ottoman mutiny in 1909

Mr Erdogan has called the micro-blogging site a "menace" used to spread "lies".

Sit-in

Earlier this week, Deputy PM Bulent Arinc apologised for police violence in the original protest, which took place a week ago.

Protest representatives who met Mr Arinc on Wednesday presented a list of demands, which included the dismissal of police chiefs, a ban on the use of tear gas, the release of detained protesters, the sacking of Istanbul's governor, and the scrapping of the plans for the redevelopment of Gezi Park.

Opponents of the plan say the park is of the few green areas left in central Istanbul - many had been camping out there for several days in protest.

But Mr Erdogan has repeatedly said the project would go ahead, and that the historic Ottoman-era military barracks would be rebuilt on the site as planned.

The protests come as Turkey prepares to host an international conference focused on its relations with the EU on Friday.

Mr Erdogan is to make the opening speech at the event, which will be attended by the EU's Commissioner for enlargement, Stefan Fuele, British ex-foreign minister Jack Straw and representatives from other member states.

Negotiations with the EU have stalled in recent years because of concerns over freedom of speech, treatment of religious minorities, women's and children's rights, civilian control of the military and long-running tensions with Cyprus.