The assailant, who has not yet been identified, opened fire inside the high-end Reina nightclub at the busy Besiktas area, Turkish state-run news agency Anadolu reported.
The gunman, dressed as Father Christmas and speaking Arabic, changed his ammunition clip several times during the gory shooting spree, Xinhua news agency reported. The killer escaped.
According to Istanbul Governor Vasip Sahin, the man shot dead a police official guarding the club’s gate and then attacked as many as 400 people gathered inside to celebrate the new year.
“It was a cruel, cold-blooded act,” CNN quoted the Governor as saying.
“We are face to face with a terror attack,” Interior minister Suleyman Soylu told the media.
Twenty-one of the dead had been identified, Soylu said. Of these, 16 were foreign nationals and five Turkish.
The US called it a terror attack, making it the first of 2017.
Soylu said: “The efforts to locate the terrorist are ongoing. Security forces have begun the necessary operations. God willing, (the attacker) will be apprehended soon.”
No group has claimed responsibility for the massacre.
Witnesses at the club heard a loud noise and then a security official told everyone to get out.
According to one witness who survived by hiding himself, he did not know how many attackers were there but he saw at least one gunman.
“I got shot in the leg, man,” he said while being taken into an ambulance. “These crazy people came in shooting everything.”
Turkish media said some people jumped into the sea to escape as the night club is close to the Bosporus Strait, prompting a rescue operation by the Coast Guard.
Besiktas is known for its expensive, upper-middle class neighbourhoods. The area had been under heavy police security for new year celebrations.
Reina is one of the first clubs to open in the neighbourhood and remains a touchstone for Istanbul’s exclusive nightlife.
Turkey has endured a recent wave of terrorist attacks, leaving many people wary.
“This attack is, of course, a horrible development, but not shocking to many Turks who chose to stay inside this new year eve,” said Aykan Erdemir, a former member of the Turkish Parliament.
He said the latest attack seemed similar to what happened at the Bataclan, a Paris concert hall that was attacked by gunmen in 2015.
“This is an attack on Western lifestyle. This is an attack on Turkey’s secular, urban way of living. And this will simply fuel the ongoing cultural clashes, the ongoing polarisation in Turkey,” Erdemir said.
The US State Department said the attacks on an NATO ally “only reinforce our strong determination to work with the government of Turkey to counter the scourge of terrorism”.
The US embassy in Turkey warned citizens to avoid the area where the attack occurred.
Turkey faces numerous battles across different fronts. Not only has the Syrian conflict and refugee crisis spilled over into Turkey, but Ankara is also battling the Islamic State and Kurdish militants.