Police detained the attacker, identified as 26-year-old Ruslan Kulikbayev, in a shootout on a busy central street after he had gone on the rampage, attacking a police station and an office belonging to the KNB security service.
Kulikbayev had been imprisoned before for robbery and illegally possessing weapons and had "became close to Salafists" in prison, KNB security service head Vladimir Zhumakanov told a Security Council meeting.
Salafists adhere to an ultra-conservative form of Islam.
The shootings will stoke fears of a growing Islamist threat to the oil-producing nation of 18 million people. Last month, men the authorities said were Islamic State sympathizers attacked gun stores and a military facility, killing seven.
Thousands of nationals from Central Asian nations are known to be fighting alongside Islamic State militants in Syria and Iraq, and the authorities have long warned they could return and carry out attacks on home soil.
Kazakhstan is far more prosperous than its post-Soviet neighbors and has been ruled with a firm hand by President Nursultan Nazarbayev since 1989.
But the fall in global oil prices has hit its economy hard and there have been rare outbreaks of violence and public protests since April, initially caused by discontent over proposed land reforms but swiftly attracting others unhappy about wider issues.
Interior Minister Kalmukhanbet Kasymov told the same Security Council meeting that police had first believed that the attacker had accomplices, but had later learned that another man they had detained was driving a car under duress at gunpoint.
Nazarbayev, who chaired the meeting, called the attacks a terrorist act and ordered tighter security in public areas.
Five witnesses told Reuters they had heard gunshots in three parts of Almaty, the mainly Muslim nation's largest city.
"We saw a man with a rifle," one shop worker said by phone. Footage uploaded to the Internet showed a man pointing an assault rifle at a car he tried and failed to stop.
Interior Minister Kasymov said the attacker had shot a policeman guarding a police station, taken his automatic rifle and then opened fire at others, killing one civilian and wounding several policemen.
Kulikbayev then hijacked a car and went to a KNB building where he shot two more policemen. He hijacked another car, according to Kasymov, before engaging police in the final shootout after which he was captured.
Kasymov said the gunman had also killed a woman the previous night.
A spokeswoman for the state anti-terrorist center told reporters seven people had been wounded in the shooting spree.
The KNB, successor to the Soviet-era KGB, said last month it had detained several members of a group planning "terrorist acts using improvised explosive devices" in the Karaganda region of central Kazakhstan. One suspect blew himself up.