ISTANBUL — When a lone gunman murdered dozens of New Year’s revelers early Sunday, he targeted a symbol of a cosmopolitan Istanbul that is increasingly under threat: a dazzling nightclub where people from around the world could party together, free from the mayhem and violence gripping the region.

It was there, at the Reina nightclub on the Bosporus — a hot spot for soap opera stars and professional athletes, Turks and well-heeled tourists — that those hoping to move past a particularly troubled year died together.

The assault was the second in two weeks in Turkey, and it further exposed the fault lines in a country that is increasingly tearing apart amid terrorist attacks and political instability.

With the gunman still on the loose Sunday night and a nationwide manhunt underway, the killings brutally highlighted a dilemma for Turkey’s authoritarian president, Recep Tayyip Erdogan: Even though he has cracked down on opponents and put in place security measures to bring stability to his rattled country, the attacks keep mounting.

“I don’t know what to say,” said Zeynep Ozman, whose brother, Ali, was wounded in the attack. “I don’t want to say anything political, but this can’t be accepted as the new norm. Terrorism is everywhere now, and the government has no control. Something needs to be done. There is no life left in Istanbul.”

Image

Relatives of victims of the attack at an Istanbul nightclub mourned on Sunday.

1 / 8

Turkey has been reeling for several years now, as it has been increasingly drawn into the Syrian civil war. By opening its borders to foreign fighters trying to reach Syria, critics say, it inadvertently supported the rise of the Islamic State, which is now carrying out attacks within Turkey. Then, in 2015, a stalled war with Kurdish militants was renewed, and this summer, Turkey suffered from an attempted coup.

The attack on Sunday morning — a strike on the Western, urbane face of Istanbul — is likely to further diminish Turkey’s democracy by giving Mr. Erdogan a freer hand to expand his crackdown on opponents, which accelerated after the coup attempt. It is also likely to erode the country’s economy, which has already suffered because of a decline in tourism and foreign investment.

“Nothing that the government is doing is helping make Turkey more secure,” said Asli Aydintasbas, a prominent Turkish writer and a fellow at the European Council on Foreign Relations. “The crackdown on domestic dissidents is further destabilizing the country, and when it is not destabilizing, it is increasing the dangerous polarization here.”

On Sunday, Mr. Erdogan vowed in a statement that the fight against terrorists would bring the country together.

“They are working to destroy our country’s morale and create chaos by deliberately targeting our nation’s peace and targeting civilians with these heinous attacks,” he said. “We will retain our coolheadedness as a nation, standing more closely together, and we will never give ground to such dirty games.”

As it had after other recent attacks, the government imposed a news blackout, saying news outlets should report only official statements.

No group claimed responsibility for the attack, which killed at least 39 people, including at least 25 foreigners, according to Turkey’s state news agency. But threats against Turkey from the Islamic State and its supporters have increased, and a senior United States official said on Sunday that the emerging assessment of both the American and Turkish authorities was that the Islamic State was responsible for the attack, or had at least inspired the gunman.

Still, the Islamic State, which Turkey is fighting against in Syria, is just one of many threats the country faces.

Even before the Arab Spring revolutions six years ago, Turkey sought to set itself apart and shape events around the region with its so-called zero problems with neighbors foreign policy.

Now, all that has changed. Turkey, a member of NATO, has been engulfed by the dark and destabilizing forces gripping the Middle East and the surrounding regions, where everything seems to converge: terrorism, the migrant crisis, the rise of authoritarianism.

The renewal of a long war between the Turkish government and ethnic Kurdish militants has left cities in the Kurdish-dominated southeast in rubble and brought terror to the heart of Turkey’s cities. A bombing at a soccer stadium in Istanbul in December that killed dozens was just the latest attack claimed by a Kurdish terrorist group.

The government pinned last summer’s failed coup on the followers of a rival to Mr. Erdogan, the Muslim preacher Fethullah Gulen, who lives in exile in Pennsylvania. That was followed by a countercoup engineered by Mr. Erdogan, in which tens of thousands of people he said were linked to Mr. Gulen — police officers, soldiers, teachers, civil servants and others — were either arrested or purged from their jobs.

Image

Victims’ relatives outside the morgue in Istanbul. The Reina nightclub is popular with tourists, and at least 25 foreigners were killed.CreditDHA-Depo Photos, via Associated Press

And less than two weeks before Sunday’s attack, an off-duty police officer assassinated the Russian ambassador to Turkey at an art gallery in Ankara, saying he was exacting revenge for Russia’s role in bombing civilians in the northern Syrian city of Aleppo. The killing came amid a rapprochement between Turkey and Russia, which had indicated that Mr. Erdogan, instead of continuing to push for the ouster of President Bashar al-Assad of Syria, was now leaning on Russia, Mr. Assad’s most important ally, to bring peace to Syria.

The assassination and the deadly nightclub attack have raised questions about how able Turkey’s intelligence forces are to keep the country safe.

With such a harrowing year coming to a close, many Turks were eager for New Year’s Eve, as if turning the page on the calendar might signal a fresh start.

In Istanbul, where a video on social media before the shooting showed well-dressed partyers at Reina ringing in the new year with sparklers, Champagne and confetti, the gaiety lasted just a little over an hour.

Around 1:15 a.m., the gunman, armed with a rapid-fire rifle, killed a police officer guarding the club before going on a shooting rampage. In the ensuing panic, some clubgoers jumped into the Bosporus, which separates Europe from Asia.

Ms. Ozman, who visited her wounded brother in the hospital, said: “He was covered in blood. I barely recognized him at first. He is in complete shock.”

She said her brother had told her that when the shooting started, he threw himself on the floor and felt things falling on him: bodies, tables, glass. She said he might have been saved by bodies that acted as shields against further shots.

The gunman’s identity and motives remain unclear, but one witness said he had heard the man shout “God is great” in Arabic.

Even with so much uncertain, the attack on Reina, which is perhaps Istanbul’s most famous nightclub, seemed to symbolize one of Turkish society’s deepest divides, between the secular and the pious — a fissure that has grown deeper under Mr. Erdogan, an Islamist who has expanded religious schooling and sought to restrict alcohol sales.

Some on social media were quick to point out the rhetoric against New Year’s celebrations that had come from Islamist corners of Turkey. A recent Friday sermon prepared by the government’s religious authority said that New Year’s revelry belonged to “other cultures and other worlds.”

Another passage of the sermon read, “We shall not forget that it is never suitable for a believer to forget himself and his aim of creation after a year passes from the stock of life, to exhibit illicit manners and behaviors that don’t comply with our values.”

In the aftermath of the attack, Prof. Howard Eissenstat, an expert on Turkey at St. Lawrence University, wrote on Twitter: “Disturbing + not very difficult line to draw between official Turkish anti New Years campaign + tonight’s violence. Rhetoric has consequences.”

Video

On Sunday, Turkish officials revealed latest information about the attacker who shot scores of people at an Istanbul nightclub on New Year's Eve and remains on the loose, and said police were doing everything to find him.CreditCreditReuters..

Emre Eytan Can, 34, an investment banker from Istanbul, said he was a regular at Reina, although he was not there on New Year’s Eve.

“I guess it is a target because it’s full of high-class Turks and foreigners,” he said. “And it’s a place where people let their hair down and drink, which is not in line with Islam.”

Turkey’s troubles had already led to a sharp decline in Western tourists, but visitors from the Middle East, perhaps because they are accustomed to terrorist threats at home, have kept coming. News of the attack quickly reverberated around the region, with citizens of Israel, Jordan, Lebanon, Saudi Arabia and Tunisia among the victims, along with people from Belgium, France and India.

By Sunday afternoon, the by-now familiar rituals of grief that follow terrorist attacks were in full swing, with consulate officials and grieving families converging at an Istanbul morgue, where local officials had set up tea stands outside in the bitter cold.

A Lebanese woman, Stephanie Deek, was there with her husband to identify a friend from Lebanon, Haykal Mousallem, a newlywed who had been celebrating the holiday in Istanbul with his wife.

The wife was safe, but Mr. Mousallem, who had jumped into the Bosporus to escape the killer, was dead.

“I am so sad,” Ms. Deek said. “I cannot describe how I feel. I did not expect to find him here. I thought he was just missing.”

Reporting was contributed by an employee of The New York Times from Istanbul; an employee of The New York Times from Nevsehir Province, Turkey; Sewell Chan from London; and Eric Schmitt from Washington.

A version of this article appears in print on , on Page A1 of the New York edition with the headline: Massacre at Nightclub Exposes Deepening Fault Lines in Turkey. Order Reprints | Today’s Paper | Subscribe