Security forces say Afghan troops ended a 12-hour attack by the Taliban on a hotel outside Kabul, in which at least 20 people died.
Insurgents attacked the Spozhmai Hotel in the Lake Qargha area on Thursday night, taking many hostages.
Kabul's police chief says 15 civilians, including hotel guests, died and all five known insurgents were killed.
The Taliban claims credit for the attack, saying the hotel was used by wealthy Afghans and foreigners for "wild parties".
Lake Qargha is on the outskirts of Kabul and is favoured by residents of the Afghan capital for day trips and family outings.
The Taliban say they were attacking an "immoral" lakeside hotel.
In fact they picked an easy target - Afghan families, celebrating the weekend, by a lake which offers some relief from the heat and dust of Kabul, the BBC reports. The unarmed guests were taken hostage by men with machine guns and rocket-propelled grenades.
The insurgents said this was a hotel frequented by foreigners, but journalists at the scene report though some foreigners do visit the area, they are usually on day trips, and few stay overnight. There aren't foreign troops in the area.
Despite the loss of life, this falls far short of the large-scale attacks which have taken place in the Afghan capital,the BBC says. It appears designed to inflict as many casualties as possible, and grab headlines.
Afghan security forces, mentored by foreign troops, tackled the insurgents. It took them 12 hours to kill all the attackers, and there was foreign air-support, but Afghan forces were in charge.
In addition to the five militants, those killed included civilians, hotel guards and a police officer.
Dozens of people were taken hostage.
The gunmen, armed with rocket-propelled grenades and heavy machine guns, launched the attack on the hotel late on Thursday, officials say.
Maihan Saeedi, who left the area shortly before the attack began, told the BBC the hotel was full of civilians, including women and children.
"When we left the hotel, we heard gunfire as we reached one of the [three security] checkpoints near the hotel," he said.
"I'm completely shocked at how people managed to cross these checkpoints - it really raises questions over the levels of security, which is all commercialised."
He said one of his friends inside the hotel told him by phone that people were trying to escape by jumping out through the windows and into the lake.
"It just shows that the Taliban are there to kill civilians," Mr Saeedi said.
The security operation was led by Afghan security forces, with support from the US-led coalition.
In recent months, the Afghan army and police have taken the lead in battling some of the most challenging insurgent attacks, winning praise and a measure of support from the Afghan population.
Violence has recently increased across the country, with at least three US soldiers and about 20 Afghans killed in a series of attacks over the past seven days.
The attacks come as NATO gradually hands responsibility for security to Afghan forces, ahead of the departure of combat troops in 2014.