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.
"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."
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.
Turkey is part of the US-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, demoralise our people, and destabilise 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.
US President Barack Obama expressed condolences and directed his team to offer help to the Turkish authorities, the White House said. President Vladimir 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 neighbourhood 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.
"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 US intelligence reports suggested a possible attack.
Turkey faces multiple threats including spill over 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.
On Dec 28, the Nashir Media Foundation, which backs Islamic State, urged sympathisers 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 spokesperson 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.