In the 1990s, under Turkey’s first Islamist prime minister, Necmettin Erbakan, Mr. Erdogan oversaw a local commission in charge of the mosque project, but the idea was anathema to Turkey’s secular elite, who could still count on the military to safeguard the country’s secular underpinnings.

A local news article published in January 1997 reported that secular Turks objected to the mosque because it would “symbolize the power of the Islamists over Taksim as well as the whole country.” Those words could easily be spoken by today’s protesters.

Ayse Hur, a historian and columnist for the newspaper Radikal, said, “The circles that oppose the project of a mosque at Taksim or the barracks may be interpreting this as an attempt to rewrite the official secular history.”

Ms. Hur added, “We know how the government adores Ottoman history and how hostile they are toward the history of the republic.”

So, Ms. Hur and others say, it was mere happenstance that the antigovernment protests that have shaken Turkey over the last several weeks began with a sit-in to save Gezi Park, which was never a particularly special place for most Istanbul residents, and was thought to be dangerous and a nighttime hangout for drug users.

But as the government began bulldozing trees, it came to symbolize for thousands of aggrieved citizens the hubris and rising authoritarianism of a government now in power for more than a decade and determined to forge ahead with the even more controversial mosque project.

Mr. Erdogan has a vision of reshaping Taksim not just with the mosque, which would be built near the French consulate, but also by creating a vast piazza by knocking down a row of kebab and schwarma shops that would create a pedestrian space between the mosque and an Orthodox church, a juxtaposition meant to symbolize Ottoman tolerance for minority, non-Muslim religions.