Five people were today gunned down in attacks on a police station and a security building in Kazakhstan's largest city Almaty with security forces arresting two men in connection with the assaults.
Kazakhstan's National Security Committee (KNB) declared its "anti-terror" operation over in the financial capital after detaining the two suspects.
Three police officers and two civilians were shot dead in what President Nursultan Nazarbayev called "a terrorist act".
KNB security chief Vladimir Zhumakanov said one of the suspects may have "connected" with followers of the ultra-conservative Salafi strain of Islam while in jail on theft and weapons charges.
"We are checking this information," Zhumakanov said at a televised meeting of Nazarbayev's security council, without providing further details.
The KNB announced "the conclusion of the anti-terror operation" and lowered the terror threat level from "critical" red to "moderate" yellow shortly after detaining the second of the two men.
The first suspect is accused of killing a local resident during a carjacking and attacking the police station in broad daylight, then shooting dead a police officer and seizing his gun, the interior ministry said.
A civilian also died during the shooting at the police station.
The suspect then shot dead two officers as they gave chase, before he was arrested.
"According to preliminary information, the detained man is a 27-year-old man with previous convictions," the ministry said, adding that he was also suspected of murdering a woman at the weekend.
The ministry did not immediately make public any details about the second detained suspect.
The health ministry said eight people had been admitted to hospital.
Two videos were widely shared on social networks showing a black-clad man roaming the streets of Almaty armed with a machinegun.
"I clearly heard shooting. Several shots were fired in quick succession. I was driving close to the police station at the time," a 40-year-old man who only gave his first name, Kanysh, told AFP.
Kazakh media reported a shootout at the national security committee building, but said the attack was repulsed and the building cordoned off.
Police called on Almaty residents to stay in their homes and several major banks and supermarkets closed their doors, while the city's airport tightened security during the attacks.
Kazakhstan had already been on a "yellow level" threat alert after deadly shootings shook a town in its northwest in June.