P1 BP985 TURKNE G 20140501185300

A woman in Ankara shows her identity card Thursday as riot police used water cannons during clashes with antigovernment protesters. Agence France-Presse/Getty Images

ISTANBUL—Turkish Prime Minister Recep Tayyip Erdogan rode around Google Inc.GOOGL -0.87% headquarters last spring in the company’s self-driving car, tried on Google Glass eyewear and vowed to keep digitizing the economy in the country he has ruled since 2003.

Since then, the 60-year-old Mr. Erdogan has turned his democratically elected government into one of the world’s most determined Internet censors.

His political party passed laws letting him shut down websites without a court order and collect Web browsing data on individuals. He put a veteran spy in charge of Turkey’s telecommunications regulator.

View Graphics

P1 BP987 TURKNE D 20140501185407

He also has blocked dozens of websites.Twitter Inc. TWTR -0.79% was banned for two weeks in late March and early April, and Google’s YouTube video-sharing service has been dark since March 27. An opposition newspaper columnist and academic was sentenced Tuesday to 10 months in jail for a tweet that insulted the prime minister, while 29 defendants are on trial on allegations that include using tweets to organize protests and foment unrest last year.

“Let people say whatever they want, we will take care of this ourselves,” Mr. Erdogan said after blocking Twitter.

Tensions were high Thursday as protesters clashed with police trying to enforce a ban on the traditional march to Istanbul’s Taksim Square, long symbolic as a place of dissent on May Day. Some critics of Mr. Erdogan say privately that they feel more nervous about making antigovernment statements. In cafes and bars here, people compare technical workarounds aimed at dodging the government’s website blockages and surveillance efforts.

P1 BP986 TURKNE G 20140501174711

New graffiti: ‘Don’t change DNS settings, change the government.’ Ayman Oghanna for The Wall Street Journal

Mr. Erdogan’s shake-up, a rapid-fire response to a power struggle with political enemies, has left Internet companies and government officials from Washington to Brussels worried that Turkey could become a template for other countries where leaders want to rein in the Internet without cracking down with as much force as China or Iran.

Iran is building what it calls a “halal” intranet to replace the Internet, and Chinese officials have imposed a censoring and filtering system known as the Great Firewall. In Turkey, Mr. Erdogan wants unfettered Internet access that can be blocked swiftly if Turkey’s intelligence agency spots something it believes is a threat.

“This is a test case for a new authoritarian model of Internet censorship,” says Zeynep Tufekci, a Turkish national who is an Internet specialist at the University of North Carolina at Chapel Hill.

Turkey’s moves appear to differ from a nonbinding statement of “important values”agreed to last week by dozens of governments and groups, including Turkey, at a meeting on Internet governance. “Everyone should have the right to access, share, create and distribute information on the Internet,” they concluded.

BN CP834 0501tu G 20140501133041

A man sweeps a street in Istanbul in front of a wall covered with gray paint. Government opponents use graffiti to spread instructions about how to evade an Internet crackdown, but authorities return with more gray paint to cover up the graffiti. Ayman Oghanna for The Wall Street Journal

Mr. Erdogan backed down from the Twitter ban after it was overturned by Turkey’s top court. But officials now are demanding that Twitter move faster to implement orders to block the accounts of specific users.

Twitter has said it is in an “ongoing dialogue” with Turkish authorities, while Google has filed appeals in three courts to end the YouTube ban. A Google spokesman said in an emailed statement: “It is obviously very disappointing to people and businesses in Turkey that YouTube is still blocked.” In January, YouTube and Twitter were the third- and sixth-most-popular websites in Turkey, according to trade group IAB Turkiye.

Some of the world’s most visible Internet companies are grappling with how far they are willing to go to accommodate Mr. Erdogan’s government in return for continued access to the country. The dilemma is aggravated because Turkey is emblematic of the emerging markets where tech companies are looking for a big growth spurt.

BN CP835 0501tu G 20140501133223

A woman uses a laptop computer near a poster of the 15-year-old boy who died nine months after being hit by a tear-gas canister fired by police while on his way to buy bread. YouTube has been blocked in Turkey since March 27, but computer users are trying to evade the ban. AFP/Getty Images

Last year, online-advertising spending in Turkey reached $615 million, about 1.4% of the U.S. total, but grew more than a third faster in local-currency terms, according to data from IAB Turkiye and Interactive Advertising Bureau.

Since the crackdown, the number of formal requests to Google and Twitter to remove content objected to by government officials has surged, pressuring the companies to comply or risk recurring blackouts.

In addition, the same law that gave Mr. Erdogan the power to shut down websites allows Internet service providers in Turkey to block individual Web addresses even if tech companies refuse.

Turkey’s parliament, controlled by the prime minister’s Justice and Development Party, passed April 17 a separate law letting the Turkish spy agency demand without a court order any data deemed threatening to national security. That could include individual Web browsing activity, email and text messages, and company sales records. It isn’t clear if officials are using those powers.

Internet service providers such as Turk Telekomunikasyon AS TTKOM.IS -0.65% , in which the government owns a 30% stake, have begun using deep-packet inspection technology, which examines a computer network’s traffic and can filter posts or help identify their authors, people familiar with the matter say. The technology, supplied at least partly by Palo Alto Networks Inc. PANW -0.29% of Santa Clara, Calif., mirrors aspects of what China has used to build its Great Firewall.

BN CP831 0501tu G 20140501132659

A billboard of Turkish Prime Minister Recep Tayyip Erdogan, mounted near security cameras, is emblazoned with words than mean ‘iron will.’ Ayman Oghanna for The Wall Street Journal

Mr. Erdogan’s office and Turkey’s telecom ministry and regulator didn’t respond to phone calls or emailed questions seeking comment about the changes. Turk Telekom says in a statement that it has complied with Turkish laws. A Palo Alto spokeswoman couldn’t be reached.

Turkish government officials have said repeatedly that the changes are designed to protect individual privacy and family values. Mr. Erdogan has shown no signs of backing down, especially after his party trounced the main opposition Republican People’s Party in local elections in March.

Some technology investors and startup firms say Mr. Erdogan’s restrictions could cripple a nascent boom. “I used to discuss Turkey’s Internet market and local firms with four to six foreign investors a week,” says Arda Kutsal, a former technology investment adviser who runs a tech blog called Webrazzi.

Those phone calls have stopped, he says.

Social-media companies like Twitter and YouTube “have nothing to do with freedom,” said Mr. Erdogan, who is weighing a run for president and has said he would try to make the largely ceremonial post more powerful. August’s election will be the first in which Turkish voters directly choose their president.

BN CP838 turkne G 20140501133704

After Turkey blocked access to Twitter in March, the company tweeted instructions on how to circumvent the ban. Twitter

Turkey is the latest example of the standoff between tech superpowers and governments in rising economies from Russia to Indonesia where leaders are trying to assert control over the Internet.

On Monday, Russia’s parliament passed new restrictions that would force many bloggers to reveal their identities and not disseminate extremist information. PresidentVladimir Putin is expected to sign the new laws soon.

Technology firms have asserted wide leeway to remove content from their sites but usually do so only if it violates their legal “terms of service.” Those terms include copyright violations and valid legal orders.

“When we suspend or withhold accounts, we do [so] in response to user complaints or court orders, not in response to government requests,” said Colin Crowell, Twitter’s vice president of global public policy.

If websites or tweets violate a local law or legal order, Twitter and Google often block the content—but sometimes allow users to bypass the ban with minor tweaks to their website settings. The cat-and-mouse strategy is “part of the DNA of Silicon Valley,” says a person familiar with the matter.

Officials have said Turkey’s sovereignty and national interest trump the companies’ rules, justifying the new laws and website blockages.

Several cabinet ministers have accused Twitter of tax evasion because it has no office in the country. Officials have demanded that the San Francisco firm open an office in Turkey. Doing so would make Twitter vulnerable to the new law that lets the spy agency demand information without a court order.

In an effort to ease tensions, Mr. Crowell and other senior Twitter staff members met in mid-April with Turkish officials. Twitter refused to open a local office but agreed to implement court orders quickly.

Police and marchers clashed in the streets of Istanbul on Wednesday as thousands of marchers tried to reach Taksim Square for a May Day rally despite a government ban. Via The Foreign Bureau, WSJ’s global news update. Photo: AP

“Our decisions to open offices around the world are based upon whether the underlying economic climate justifies it,” Mr. Crowell said. Since the meeting, Twitter has implemented at least a dozen Turkish court orders to withhold accounts or block tweets.

In contrast, Mr. Erdogan’s visit last year to Silicon Valley was buoyed by a budding spirit of compromise and mutual opportunity. He visited Apple Inc.,AAPL -0.26% Google and Microsoft Corp.MSFT -0.78%

In 2011, the Turkish leader courted Microsoft, Hewlett-Packard Co. and other tech companies to join a classroom digitization project named Fatih—or “conqueror,” after an Ottoman sultan. Government officials tried to censor what could be viewed on the tablets, but students found a way to breach the device’s firewalls to play games.

In late 2012, Google launched a local version of YouTube, a move that allowed the company to block access to some videos within Turkey while making them available elsewhere. Turkey dropped its demand that YouTube block globally all videos critical of the Turkish republic’s founder, Mustafa Kemal Atatürk.

Mr. Erdogan’s position began to shift dramatically less than a month after coming home from Silicon Valley. Tweets and other social media helped fuel antigovernment protests across Turkey that left seven people dead. The prime minister called Twitter a “menace to society,” and his political party set out to fight critics online with a 6,000-person team of loyalists.

Last December, leaks of wiretapped recordings posted anonymously on Twitter and YouTube implicated dozens of Mr. Erdogan’s closest allies and family members in allegedly corrupt practices.

He denied the claims, said the tapes were doctored and accused Fethullah Gulen, a U.S.-based Turkish imam with millions of followers, of masterminding the mess. The imam says he isn’t responsible for the recordings

Despite criticism from Western allies and fistfights in Turkey’s parliament, lawmakers approved Mr. Erdogan’s move to empower the government to shut down websites without court orders. “The law was drafted hastily and with no consultation,” says Gokhan Candogan, an executive at the Ankara Bar Association. The group has filed an appeal with Turkey’s constitutional court.

The shake-up spread to Turkey’s telecom regulator, where five top managers were replaced. “Authorities walked into their offices and said: ‘Leave now. Don’t even bother taking your jackets,’ ” says one person familiar with the incident. The agency’s new boss: Ahmet Cemaleddin Celik, a longtime spy at Turkey’s intelligence service.

Under Mr. Celik, the number of requests to Internet companies to remove content has soared, including more than 15 to Twitter so far this year, up from two in the last half of 2013.

On March 20, Mr. Erdogan vowed to “eradicate” Twitter. Hours later, the telecom regulator began bouncing queries for the company’s website to an error message. Top Internet service providers in Turkey got phone calls from the agency with firm instructions: “Just block it now.”

At Twitter headquarters, employees saw the hashtag #Twitterisblockedinturkey, an alert from Turkish users, rocket to the top of the website’s hottest topics. Top officials gathered in a “virtual war room” to discuss Twitter’s options.

The company decided to tweet instructions to Turkish users on how to circumvent the ban using text messages. It had done the same thing in Venezuela earlier this year.

Internet users in Turkey worked hard to evade Mr. Erdogan’s crackdown. Graffiti painted on walls in Istanbul and other Turkish cities steered people to “open DNS” addresses run by Google. Some users hid messages by routing them through encrypted networks outside Turkey or software that connected through other users’ computers.

Turkish President Abdullah Gul, a longtime ally of Mr. Erdogan, tweeted an objection to the prime minister’s moves: “The wholesale shuttering of social media platforms cannot be approved.”

Twitter tried to both resist and acquiesce to Turkey’s demands. The company filed a court appeal to bring the site back to life, yet blocked an antigovernment account that used the handle @oyyokhirsiza—or “no vote for the thief.” Twitter officials also left a loophole that allowed Turkish users to see the tweets by changing their location settings to a different country.

Turkish authorities blocked YouTube after demanding that the company remove videos that claimed to include a recording of Turkey’s foreign minister and spy chief discussing the viability of faking an attack by Syrian terrorists to justify armed intervention inside Syria.

“We blocked YouTube to protect our national security,” Mr. Erdogan said bluntly. He said the leak was “villainous and cowardly” but hasn’t disputed the authenticity of the recording.

The shutdown came before lawyers at Google, based in Mountain View, Calif., had fully reviewed the demand. Within 24 hours, Google agreed to halt the videos in Turkey.

Moves by computer users to work around the bans led the Turkish government to tighten its grip even more. As the local elections loomed, Turk Telekom began impersonating servers owned by Google and other U.S. companies, according to Renesys Corp., a Manchester, N.H., company that monitors Internet performance. That let the telecom company redirect or block access to sites and monitor browsing activity, lawyers and Internet activists say.

Google criticized Turkey on the company’s security blog. Turkish officials haven’t publicly admitted or denied the practice, widely referred to as hijacking.

At the same time, Turkish officials prodded Google to make faster decisions about government requests to block objectionable content, people familiar with the matter say. While Google had agreed to block some of the hundreds of videos the government wanted to remove, the company resisted a push to shift more decision-making authority to employees in Turkey.

Four days after the local-election victory by Mr. Erdogan’s party, the highest court in Turkey overturned the Twitter ban as “illegal and arbitrary.” He complied but has said he doesn’t respect the ruling.

In Istanbul, graffiti with instructions on how to sidestep Internet censorship has been covered in gray paint. When the graffiti reappears, so do government authorities, armed with more gray paint.

P1-BP985_TURKNE_G_20140501185300