ISTANBUL (Reuters) - A gunman opened fire on New Year revelers at a packed nightclub on the shores of Istanbul’s Bosphorus waterway on Sunday killing at least 39 people, including many foreigners, then fled the scene.

Some people jumped into the Bosphorus to save themselves after the attacker began shooting at random in the Reina nightclub just over an hour into the new year. Witnesses described diving under tables as the assailant walked around spraying bullets from an automatic rifle.

The attack shook NATO member Turkey as it tries to recover from a failed July coup and a series of deadly bombings in cities including Istanbul and the capital Ankara, some blamed on Islamic State and others claimed by Kurdish militants.

Security services had been on alert across Europe for new year celebrations following an attack on a Christmas market in Berlin that killed 12 people. Only days ago, an online message from a pro-Islamic State group called for attacks by “lone wolves” on “celebrations, gatherings and clubs”.

“At first we thought some men were fighting with each other,” said a Lebanese woman who gave her name as Hadeel and who was in the club with her husband and a friend. “Then we heard the sound of the gunfire and ducked under the tables.

“We heard the guy screaming Allahu Akbar (God is Greatest), all three of us heard that ... We heard his footsteps crushing the broken glass,” she told Reuters. “We got out through the kitchen, there was blood everywhere and bodies.”

Officials spoke of a single attacker, a “lone wolf” in the parlance of Islamic State, but some reports citing witnesses including on social media suggested there may have been several.

The incident bore echoes of an attack by militant Islamists on Paris’s Bataclan music hall in November 2015 that, along with assaults on bars and restaurants, killed 130 people.

Nationals of Saudi Arabia, Morocco, Lebanon, Libya, Israel, a Turkish-Belgian dual citizen and a Franco-Tunisian woman were among those killed, officials said. Saudi newspaper al-Riyadh said five of the dead were from Saudi Arabia.

France said three of its citizens were wounded.

A massive security operation unfolded to track down the fugitive assailant or assailants and any conspirators.

Turkish Interior Minister Suleyman Soylu said 15 or 16 of those killed at Reina were foreigners but only 21 bodies had so far been identified. He told reporters 69 people were in hospital, four of them in critical condition.

Turkey is part of the U.S.-led coalition against Islamic State and launched an incursion into Syria in August to drive the radical Sunni militants from its borders. It also helped broker a fragile ceasefire in Syria with Russia.

“As a nation, we will fight to the end against not just the armed attacks of terror groups, but also against their economic, political and social attacks,” President Tayyip Erdogan said in a written statement.

“They are trying to create chaos, demoralize our people, and destabilize our country ... We will retain our cool-headedness as a nation, standing more closely together, and we will never give ground to such dirty games,” he said.

Reina is one of Istanbul’s best known nightspots, popular with local high society and foreigners. Some 600 people were thought to be inside when the gunman shot dead a policeman and civilian at the door, forced his way in and then opened fire.

Istanbul Governor Vasip Sahin said the attacker used a “long-range weapon” to “brutally and savagely” fire on people, apparently referring to some form of assault rifle.

Slideshow ( 37 images )

U.S. President Barack Obama expressed condolences and directed his team to offer help to the Turkish authorities, the White House said. President Vladimir Putin Putin said Russia remained Turkey’s reliable partner in fighting terrorism, according to a statement from the Kremlin.

“POLICE MOVED IN QUICKLY”

Dozens of ambulances and police vehicles were dispatched to the club in Ortakoy, a neighborhood on the city’s European side nestled under one of three bridges crossing the Bosphorus and home to nightclubs, restaurants and art galleries.

“I didn’t see who was shooting but heard the gun shots and people fled. Police moved in quickly,” Sefa Boydas, a Turkish soccer player, wrote on Twitter.

Slideshow ( 37 images )

“My girlfriend was wearing high heels. I lifted her and carried her out on my back,” he said.

Hurriyet quoted Reina’s owner, Mehmet Kocarslan, as saying security measures had been taken over the past 10 days after U.S. intelligence reports suggested a possible attack.

Turkey faces multiple threats including spillover from the war in Syria. Beside its cross-border campaign against Islamic State, it is fighting Kurdish militants in its southeast.

The New Year’s Day attack came five months after a failed military coup, in which more than 240 people were killed, many of them in Istanbul, as rogue soldiers commandeered tanks and fighter jets in a bid to seize power.

More than 100,000 people, including soldiers and police officers, have been sacked or suspended in a subsequent crackdown ordered by Erdogan, raising concern both about civic rights and the effectiveness of Turkey’s security apparatus.

On Dec. 28, the Nashir Media Foundation, which backs Islamic State, urged sympathizers to carry out attacks in Europe during the holiday period and to “replace their fireworks with explosive belts and devices, and turn their singing and clapping into weeping and wailing”.

A month ago, a spokesman for Islamic State urged supporters to target “the secular, apostate Turkish government”.

Turkey has seen repeated attacks in recent weeks. On Dec. 10, two bombs claimed by Kurdish militants exploded outside a soccer stadium in Istanbul, killing 44 people.

A car bomb killed at least 13 soldiers and wounded 56 when it ripped through a bus carrying off-duty military personnel in the central city of Kayseri a week later, an attack Erdogan also blamed on Kurdish militants.

The Russian ambassador to Turkey was shot dead as he gave a speech in Ankara on Dec. 19 by an off-duty police officer who shouted “Don’t forget Aleppo” and “Allahu Akbar”.

In June, around 45 people were killed and hundreds wounded as three suspected Islamic State militants carried out a gun and bomb attack on Istanbul’s main Ataturk airport.