Some people jumped into the Bosphorus waters to save themselves after the attacker opened fire at random in the Reina nightclub just an hour into the new year, as reported by Reuters.
Officials spoke of a single attacker but some reports, including on social media, suggested there may have been more, at least one of them wearing a Santa Claus costume which he ditched in order to escape.
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".
The Hurriyet newspaper cited witnesses as saying the attackers shouted in Arabic as they opened fire at Reina.
Read also13 Turkish soldiers killed, 48 wounded in car bomb attackTurkish Interior Minister Suleyman Soylu said 15 or 16 of those killed were foreigners but that only 21 of the bodies had so far been identified. He said 69 people were in hospital, four of them in a 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.
The Reina club is one of Istanbul's most well-known and is popular with locals and foreigners alike. It overlooks the Bosphorus Strait separating Europe and Asia in the city's cosmopolitan Ortakoy district.
As many as 600 people were thought to have been inside when the gunman shot dead a policeman at the door, forced his way in and then opened fire.
Istanbul Governor Vasip Sahin said the attacker had used a "long-range weapon" to "brutally and savagely" fire on people, apparently referring to some form of assault rifle.
U.S. President Barack Obama, on vacation in Hawaii, expressed condolences and directed his team to offer help to the Turkish authorities, the White House said.