A suicide bomber attacked a British Embassy ­vehicle in the eastern part of the Afghan capital Thursday morning, killing six, including a ­British citizen, and injuring more than 30, according to law enforcement officials.

Ten hours later, a suicide bomber and two gunmen attacked a foreign guesthouse near the compound of the International Relief and Development Organization, a humanitarian agency based in Arlington. The bomber detonated his explosives near the guesthouse as the gunmen tried to enter the compound in the affluent enclave of Wazir Akbar Khan, home to several embassies and nongovernmental and media organizations.

But guards at the compound engaged in a firefight, driving away the gunmen, Deputy Interior Minister Mohammad Ayub ­Salangi told reporters at the scene. One of the gunmen was killed, and a Nepalese guard at the compound was injured, he added. No other foreigners were wounded or killed, he said. After the attack, all the foreigners were quickly evacuated.

The two attacks were the latest in a spate of assaults targeting foreigners as most U.S. and international troops are preparing to withdraw by the end of the year. The Taliban asserted responsibility for both attacks, as it has for other bombings that have rocked the capital in recent weeks.

The attacks come during pivotal developments for Afghanistan’s future. This week, the ­nation’s parliament endorsed the signing of a bilateral security agreement, known as a BSA, that allows U.S. and international troops to remain after the end of the year. And next week, President Ashraf Ghani will travel to London for a donor conference at which he will seek billions of dollars in aid to develop the country, mired in an economic crisis.

“They want to show that, ­despite having signed BSA and being a partner with the U.S., security is not easy to come by,” said Sediq Sediqqi, an Afghan ­Interior Ministry spokesman, referring to the Taliban. “They want to show their presence. They want to demonstrate they have the strength to do this. Unfortunately, this winter they will try more of these attacks, and especially Kabul will be more a focus.”

In the morning blast, which unfolded about 10 a.m., authorities said the attacker ­detonated a car filled with ­explosives near the British ­Embassy vehicle, transforming it into a mangled mass of steel. The explosion was heard miles away, and black smoke rose from the scene, which was about a mile from the bases where foreign contractors live.

“I heard a huge blast,” said Mohammad Omar, an Afghan guard working for a construction company with an office near the scene of the bombing. “I was dazed, but a few minutes later I saw three cars destroyed and many people wounded.”

Britain’s foreign secretary, Philip Hammond, said in a statement that a British citizen belonging to the embassy’s civilian security team and an Afghan working for the embassy were killed. A second British member of the security team was injured.

“I condemn this appalling ­attack on innocent civilians ­supporting our diplomatic activity,” the statement said. “This outrage brings home to us once again the courage and perseverance of the people of Afghanistan and members of the international community who support them, who have lived together through decades of conflict.”

Gen. John F. Campbell, the American commander of the ­International Security Assistance Force, the NATO-led mission to help stabilize Afghanistan, also condemned the bombing, saying in a statement that “those who commit such murderous acts have no place in the future of this country.”

In a tweet, Taliban spokesman Zabihullah Mujahid said that the “martyrdom attack targeted foreign invaders.”

The incident was the second time this week that foreigners have been attacked in a similar fashion in the same area. On Monday, two American soldiers, including one from Maryland’s Eastern Shore, were killed nearby when a bomb attached to a bicycle exploded as their convoy passed.

The Pentagon on Wednesday said they were Command Sgt. Maj. Wardell B. Turner, 48, of Nanticoke, Md., and Spec. Joseph W. Riley of Grove City, Ohio. Both soldiers were working with the ISAF.

Attacks in Kabul, and in other parts of the country, have intensified since Ghani took office two months ago. The Taliban has ­denounced Ghani for his close ties to Washington and has launched a campaign to strike high-profile targets. In recent weeks the insurgents have tried to assassinate Kabul’s police chief and a prominent women’s rights activist. They have also repeatedly assaulted compounds inhabited by foreign contractors.