At least 59 cadets and guards have been killed in an attack by militants on a police college in the Pakistani city of Quetta, officials say.
Three militants wearing suicide bomb vests entered the college late on Monday, reportedly taking hostages.
A major security operation lasted for hours and all attackers were killed.
So-called Islamic State (IS) said its fighters had carried out the attack, although officials have blamed another militant group, Lashkar-e-Jhangvi.
Quetta, the capital of Balochistan province, has seen similar attacks by both separatists and various Islamist militant factions in recent years.
Hundreds of trainees were evacuated from Balochistan Police College as troops arrived to repel the militants. Local media reported at least three explosions at the scene.
"I saw three men in camouflage whose faces were hidden carrying Kalashnikovs," one cadet said according to AFP news agency. "They started firing and entered the dormitory but I managed to escape over a wall."
The police academy is home to hundreds of students and many of the cadets who died were killed in the blasts, said Maj-Gen Sher Afghan of the Frontier Corps.
M Ilyas Khan, BBC News: 'Militants hit state symbol'
This assault has clearly highlighted the woes of Pakistan's south-western city of Quetta not just because of the heavy casualties, but because it came on the very day a judicial commission investigating an earlier attack held its first hearing.
That attack in August was carried out on a "soft" target - the emergency ward of a city hospital. The militants have now hit a symbol of the state, though some still consider police to be a softer target in a region where law enforcement has largely slid under the control of the military.
It all comes against the backdrop of heightened tensions between Pakistan and its two neighbours, India and Afghanistan. A top military official claimed these attackers had handlers in Afghanistan.
But many will point to Pakistan's own alleged use of militants as a state policy, which they say has now started to backfire. Northern Balochistan has been home to Afghan Taliban who have long-standing links not only to elements within the Pakistani establishment but also to al-Qaeda and Pakistani Taliban groups that have since turned against Islamabad.
The exact sequence of events is unclear but there was intermittent exchange of fire between the attackers and security forces for several hours, according to Dawn newspaper. There were also reports of a hostage situation.
More than 100 people, mostly trainees, were injured.
Pakistan's army and the paramilitary Frontier Corps took part in the military counter-operation, which Balochistan provincial home minister Mir Sarfaraz Ahmed Bugti said was now over.
Two of the militants died after detonating their bomb vests and one was killed by security forces.
Pakistani media highlighted the nation's poor security situation after the attack, with leading TV channels changing their logos to black in a mark of respect for the victims,
Officials blamed a faction of the Lashkar-e-Jhangvi militant group and said the attackers "were in communication with operatives in Afghanistan".
However, IS said on its Amaq news agency that its fighters had carried out the attack, releasing an image purported to be of the three gunmen.
IS formed a branch for Afghanistan and Pakistan in January 2015 under Hafiz Saeed Khan. He was killed in a US drone strike in July this year.
The first suspected IS attack in Pakistan was in April 2015, when three soldiers were killed. It then claimed an attack on a bus in Karachi that killed 45 people, although the Pakistani Taliban splinter group Jundullah also said it was responsible.
IS said it also carried out a suicide bombing that killed 88 people at a hospital in Quetta in August, but that too is disputed, with another faction of the Pakistani Taliban, Jamaat-ul-Ahrar, saying it was behind the attack.
The Pakistani military has been conducting operations against militants in volatile tribal areas near the Afghan border.
Balochistan Police College
- Located about 13km from Quetta city in an area called Sariab, one of the most sensitive areas of Quetta.
- About 600 cadets stay in dormitories at college, according to local media.
- It has come under attack twice before. In 2006 six policemen were killed in five powerful explosions at the academy.
- In 2008 gunmen fired rockets into the grounds and then attacked the college.