Turkish officials on Tuesday confirmed the arrest of a suspect accused of fatally shooting 39 people at a New Year’s Eve party in an Istanbul nightclub, saying he is an Uzbek national who is linked to the Islamic State militant group and who had received training in Afghanistan.

Officials said the suspect, Abdulkadir Masharipov, was arrested late Monday in Istanbul’s high-rise Esenyurt district and detained along with four other people. He was the focus of a nationwide manhunt in several cities and had eluded police for weeks. He was shown bruised and bloody in pictures that were apparently taken after he was in custody and that local news outlets distributed.

“The perpetrator of this vile attack has been captured,” Prime Minister Binali Yildirim told reporters in Ankara, the Turkish capital. “The powers behind this will be revealed,” he added, without elaborating.

Vasip Sahin, Istanbul’s governor, said that fingerprint evidence linked Masharipov to the killings and that the suspect had “accepted his crime.”

The attack on the waterfront Reina nightclub was among the worst mass killings in recent memory in Turkey, which has been shaken by an onslaught of attacks from militants as well as Kurdish separatists.

Abdulkadir Masharipov was arrested late Monday in the New Year’s Eve attack that killed 39 people in Istanbul. (AFP/Getty Images)

[U.S. boosts support for Turkish military in Syria]

The details and surveillance footage from the brazen assault shocked the country, with the gunman blasting his way through the front entrance of the club, one of Turkey’s most famous venues, as people fell around him.

The victims included more than two dozen foreigners, mostly from countries across the Middle East, as well as a Turkish security guard who, just weeks before, survived another terrorist attack in the city.

The Islamic State quickly claimed responsibility, framing the carnage as retaliation for Turkey’s military involvement in Syria’s civil war. There, Turkish forces have battled Islamic State fighters in strongholds along the border. Turkey has also carried out air and artillery strikes on the Islamist militants.

[Opinion: How Obama pushed Turkey into Russia’s embrace]

Hundreds of Uzbek militants have flocked to join the Islamic State in Syria and Iraq, according to researchers tracking the group’s foreign fighters. Uzbek Islamic militants have been featured in the group’s propaganda videos and have carried out suicide attacks on Iraqi troops.

Turkish authorities did not say Tuesday whether Masharipov had spent significant time in Iraq or Syria. But his alleged training in Afghanistan raises questions about the potential role of the Islamic State affiliate there.

The affiliate, known as Khorasan Province, has struggled to establish a foothold and is not known to have ordered or participated in an attack outside Afghanistan.

But Uzbek militants have long fought in Afghanistan, where they were allied with the Taliban, and they have launched attacks on U.S. and NATO troops. In 2015, a faction of the Islamic Movement of Uzbekistan, which has a strong presence in Afghanistan, pledged allegiance to the Islamic State.

Sahin, the Istanbul governor, said Tuesday that Masharipov speaks four languages and was “well trained.” He was born in 1983, Sahin said.

Authorities think he arrived in Turkey last year. Turkey is home to a number of residents from Central Asian countries, with which it shares linguistic and historical ties.

After the attack, the hunt for Masharipov involved about 2,000 officers searching dozens of locations, Sahin said.

The authorities found nearly $200,000 in cash at the apartment where Masharipov was captured.

Read more:

Slain partiers came to Istanbul from near and far to celebrate the New Year

Gunman slays 39 in Istanbul New Year’s massacre

Today’s coverage from Post correspondents around the world

Like Washington Post World on Facebook and stay updated on foreign news