The attack ended when three gunmen were killed by security forces, the Taliban-run administration said.
Two foreigners were injured while trying to escape by jumping from the hotel balcony, Taliban spokesman Zabihullah Mujahid wrote on Twitter.
Kabul's Emergency Hospital, run by an Italian non-profit near the hotel in the Shahr-e-Naw area, reported receiving 21 casualties — 18 injured and three dead on arrival.
Taliban sources said the attack was carried out at Longan Hotel, where Chinese and other foreigners usually stay.
A loud blast was heard before several bursts of gunfire, witnesses told Reuters.
The hotel is reportedly popular with Chinese business visitors.
A fire later broke out at the site, with videos posted to social media showing a blaze on the building's lower floors.
The attack came a day after China's ambassador met the Afghan deputy foreign minister to discuss security-related matters and sought more protection for its embassy.
China's state-run Xinhua news agency said the attack happened near a Chinese guesthouse and its embassy in Kabul was closely monitoring the situation.
The Afghan capital has been rocked by regular attacks, particularly since the Taliban takeover last year.
Dozens of people were killed in suicide bombings in September, including at a school in a Hazara-majority neighbourhood.
Attacks take place across the country on an almost weekly basis.
Seven people were killed in a bus bombing in northern Afghanistan on Tuesday. Six others were wounded hours later in an explosion at a foreign currency exchange in the city of Jalalabad.
Although the Taliban claim to have improved security since coming to power, ISIS has claimed responsibility for several attacks.
The extremists strike civilian areas as well as mosques and religious schools affiliated with the Taliban.