Los Angeles (AFP) - A horrific attack that killed 39 revelers in an Istanbul nightclub cast a dark shadow over New Year celebrations attended by millions around the world to ring in 2017.

The shooting massacre, carried out by a gunman reportedly dressed as Santa Claus, took place despite heightened security in major cities around the world, amid fears that celebrations could present a target for terrorists.

Many of the victims of the attack on the Reina nightclub, one of Istanbul's most exclusive, were foreigners.

"The attacker -- in the most brutal and merciless way -- targeted innocent people who had only come here to celebrate the New Year and have fun," Istanbul governor Vasip Sahin said.

In New York, where a crowd estimated at nearly a million people packed into Times Square, security was very tight.

When the traditional ball dropped at the Big Apple's iconic crossroads, revelers screamed with glee and couples kissed as fireworks lit up the sky and the voice of Frank Sinatra singing "New York, New York" rang out.

Out west, tens of thousands gathered in Grand Park in Los Angeles to enjoy live music plus inflatable sculptures and a 3-D light show.

President-elect Donald Trump sent his best wishes to the American people.

"Looking forward to a wonderful & prosperous 2017 as we work together to #MAGA," Trump tweeted at the stroke of midnight, referring to his campaign slogan "Make America great again".

Following truck massacres in Berlin during Christmas and in Nice over the summer, New York deployed some 7,000 police and dozens of garbage trucks to secure the festivities from similar attacks.

"It's the best place in the world to be on New Year's Eve," said Alma Alanis, a lawyer from Mexico, who was on holiday in New York.

Sydney kicked off celebrations attended by some 1.5 million people with a spectacular fireworks display that lit up its harbor.

Crowds in Hong Kong also flocked to the waterfront to watch fireworks explode over Victoria Harbour, while in Tokyo thousands packed the streets to release balloons into the air.

Story continues

Celebrations swung into Europe with the night sky over Moscow's Red Square literally painted red by the fireworks.

And around half a million people thronged Paris's famous Champs-Elysees, where the Arc de Triomphe was lit up with a colourful countdown to 2017 and the word "welcome" in dozens of languages.

Under the watchful eye of some 2,000 military police, around two million people watched a fireworks display on Rio de Janeiro's Copacabana Beach that while impressive was shortened this year due to a severe economic crisis.

- Year of political shocks -

The night was the last in a year of political shocks, from Britain's vote to leave the European Union to the election of Trump in the United States.

It has also been a year of celebrity deaths from David Bowie to Prince and Muhammad Ali.

2016 was also a year of bloodshed and misery that has seen the war in Syria, Europe's migrant crisis and numerous terror attacks dominate the headlines.

The violence continued on Saturday, with twin bomb blasts killing at least 27 in a busy market area in central Baghdad.

But this did not stop people from flooding the streets of the Iraqi capital to celebrate and families in evening dress headed to swanky hotels for parties.

In the shattered Syrian city of Aleppo, 20-year-old student Abdel Wahab Qabbani was also determined to see in 2017 in a positive frame of mind.

"The last two years, I didn't go out for New Year. This time, I'm going to party," he said.

- Extra security -

But revelers everywhere did have to contend with reinforced security measures.

There were some 2,000 extra officers in Sydney after a man was arrested for allegedly making online threats against the celebrations.

Following the deadly attack on a Berlin Christmas market on December 19, the German capital beefed up security, deploying extra police, some armed with machine guns.

However, visitors seemed undeterred by recent events as they gathered under a freezing Berlin sky for a series of concerts ahead of a midnight fireworks display.

Paris saw fireworks again, after muted 2015 celebrations following the massacre of 130 people by jihadists in the French capital.

In London, more than 100,000 people lined the banks of the River Thames to watch a spectacular 12-minute fireworks display set to a soundtrack featuring music by Bowie and Prince.

Mayor Sadiq Khan proclaimed that despite the vote for Brexit, "London is open to the world."

Revelers got one extra second to enjoy the night's festivities.

At the stroke of midnight, there was a "leap second" decreed by the International Earth Rotation and Reference Systems Service to allow astronomical time to catch up with atomic clocks that have called the hour since 1967.