Suicide bombers and gunmen attacked the communications ministry in central Kabul on Saturday, officials said, in an hours-long assault that destroyed weeks of relative calm in the capital.
The Taliban said it had "nothing to do" with the attack, which left some 2,000 people stranded in the tall office building for hours at the start of the Afghan work week.
No other group claimed immediate responsibility, but the Afghan branch of the Islamic State group has previously carried out multiple deadly attacks in the capital.
"As a result of today's explosion/attack in Kabul city, two people have been martyred (killed) and 6 others are wounded," the health ministry spokesman wrote in a tweet, adding 3 of the injured were women.
AFP journalists heard one big blast around 11:40 am (0710 GMT), followed by sporadic gunfire for hours afterwards.
"The information that we have is four attackers have placed themselves near the communication ministry and are engaged in gun battles with the Afghan security forces," Amanduddin Shariati, a security official in Kabul told news agency AFP.
By about 5:00 pm (1230 GMT), the interior ministry declared the assault over.
"Operations finished. All suicide bombers killed & more than 2000 civilians staff rescued," the ministry said on Twitter.
Panicked workers inside the 18-storey building, believed to be Kabul's tallest, moved up to the top floor as gunmen and Afghan security officials battled lower down.
One woman said she had been in a group of about 30 people on the 10th floor when the assault started, then was told to move up to the 18th floor as gunfire increased. They were all eventually rescued by commandos.
"Women were screaming and children of the kindergarten were the first to be evacuated," the woman, who did not want to be named, told news agency AFP.
Afghan authorities gave conflicting reports during the incident. The information ministry initially said three suicide bombers had attacked a post office building at the ministry.
General Sayed Mohammad Roshan Dil, the Kabul police chief, said four attackers had been wearing police uniforms and had targeted a shrine near the ministry.
Footage on local television showed a small plume at the building, and people climbing out windows on a lower level.
The presidential palace said in a statement "the enemies of Afghanistan have conducted a terrorist attack".
"Once again they have created fear and have killed or wounded a number of innocent countrymen," the statement read.
The communication ministry is located in downtown Kabul, about two kilometres (1.25 miles) from the green zone, a heavily fortified compound for foreign embassies.
The area is the city's main commercial zone and is home to a large hotel.
Aside from a grenade attack on a military vehicle last week and persistent crime, the capital has in recent weeks enjoyed a period of relative calm.
Last year however saw a string of attacks including one where a massive bomb concealed in an ambulance killed more than 100 people.
The attack comes a week after the Taliban announced their annual spring offensive and amid ongoing fighting across Afghanistan.
It illustrates the sprawling nature of Afghanistan's conflict, and the obstacles to peace even if a deal is reached with the Taliban.
This week in the Qatari capital Doha, a summit planned between the Taliban and officials from across Afghanistan was scrapped at the last minute due to bickering over who should attend the conference.
The collapse comes at a critical time and amid continued bloodshed in Afghanistan, where the Taliban now control or influence about half of Afghanistan and 3,804 civilians were killed there last year, according to a UN tally.
Taliban officials are separately negotiating with the United States, which wants to forge a peace deal with the terrorists.