A gunman suspected of killing 39 people during a New Year's attack on an Istanbul nightclub was caught in a police operation, authorities said early Tuesday.

The suspect was captured in a special operations police raid on a house in Istanbul's Esenyurt district, private NTV television reported. The broadcaster said he had been staying in the house belonging to a friend from Kyrgyzstan.

Istanbul's governor says that suspect, an Uzbekistan national who trained in Afghanistan, confessed to carrying out the attack.

<a href="https://twitter.com/hashtag/BREAKING?src=hash">#BREAKING</a> <a href="https://twitter.com/hashtag/Istanbul?src=hash">#Istanbul</a> Gov.: suspect is Abdulkadir Masharipov,Uzbek,born in 1983. Knows 4 languages, trained in Afghanistan. <a href="https://twitter.com/CBCAlerts">@cbcalerts</a> <a href="https://twitter.com/hashtag/Reina?src=hash">#Reina</a> —@nilkoksalcbc

Abdulkadir Masharipov is believed to have entered Turkey in January 2016, governor Vasip Sahin said.

Sahin said "it is clear that this was carried out in the name of Daesh," using the Arabic acronym for the militant group Islamic State of Syria and Iraq (ISIS).

The Islamic State group has claimed responsibility for the nightclub massacre, saying the attack in the first hours of Jan. 1 was in reprisal for Turkish military operations in northern Syria.

Among the dead was a Canadian woman, 29-year-old Alaa Al Muhandis of Milton, Ont.

Prime Minister Binali Yildirim told reporters in Ankara expressed hope that the interrogation would unveil the "forces" behind the attack.

A handout photo released on Monday by the Turkish police and obtained through Depo Photos shows the main suspect of the Reina nightclub shooting after he was arrested by police early Tuesday in Turkey. (Depo/EPA) "The vile terrorist who attacked the place of entertainment on New Year's eve and led to the loss of so many lives has been captured," Yildirim said.

Dogan news agency earlier Monday published what it said was the first image of the attacker. It showed a bruised, black-haired man in a grey, bloodied shirt being held by his neck. Private NTV television said the gunman had resisted arrest.

Police established his whereabouts four or five days ago, but delayed the raid so they could monitor his movements and contacts, NTV reported.

The television channel also broadcast footage showing plain-clothed police taking away a man in a white top and sweat pants, forcing his head down.

Turkish Foreign Minister Mevlut Cavusoglu posted a Twitter message thanking the interior minister, Suleyman Soylu, police and intelligence organizations "who caught the Reina attacker in the name of the people."

Earlier in the day, Turkish Deputy Prime Minister Numan Kurtulmus said the Reina nightclub attack had been carried out professionally with the help of an intelligence organization, a claim he had made in the first days after the attack.

<a href="https://twitter.com/hashtag/breaking?src=hash">#breaking</a> <a href="https://twitter.com/hashtag/Istanbul?src=hash">#Istanbul</a> Gov.: Police also seized $197000USD, 2 weapon cartridges,2 drones, sim cards during arrest of <a href="https://twitter.com/hashtag/Reina?src=hash">#Reina</a> suspect <a href="https://twitter.com/CBCAlerts">@CBCAlerts</a> <a href="https://t.co/t7ZBMYqQUo">https://t.co/t7ZBMYqQUo</a> —@nilkoksalcbc

Hundreds of people were gathered at the swanky Reina nightclub to celebrate the end of a tumultuous 2016 only to become the first victims of 2017. The gunman shot a police officer and a civilian outside the club, then stormed the premises.

Most of the dead in the attack on the upscale club were foreign nationals, from the Middle East. The gunman had reportedly left Reina in a taxi.