KABUL — A gunman wearing an Afghan army uniform opened fire Thursday on participants in a meeting with the top U.S. commander in Afghanistan, killing three senior provincial officials and wounding at least three Americans. Gen. Austin “Scott” Miller, the target of the attack claimed by the Taliban, escaped unharmed.

Among those killed in the assault inside the governor’s compound in southern Kandahar province was the region’s top police general, Abdul Raziq, who was seen as the most powerful man in southern Afghanistan.

U.S. military officials confirmed that an American soldier, a contractor and another civilian were wounded in the attack, which occurred shortly after a high-level meeting attended by Miller.

At a news conference later Thursday, Afghan President Ashraf Ghani confirmed that Abdul Raziq and the Kandahar provincial intelligence chief “were martyred.”

The Afghan Interior Ministry said the provincial governor, Zalmai Wessa, was wounded in the shooting and was rushed to a hospital, where he was later reported to have died. The ministry said Miller was not hurt and returned to Kabul.

A Taliban spokesman, Qari Mohammad Yusuf Ahmadi, said in an email to journalists that the group carried out the attack and that Miller was among the main targets. Ahmadi asserted that Miller had been killed, which U.S. military officials denied. Ahmadi claimed that in addition to Abdul Raziq, whom he described as “the savage commander of Kandahar,” the dead included Wessa and Kandahar’s intelligence chief, Abdul Momin.

The attacker opened fire as the officials were in the governor’s compound after a meeting about security for crucial parliamentary elections set for Saturday, officials said.

The lone attacker was killed after fatally shooting Abdul Raziq and wounding several of his bodyguards, Afghan and U.S. security officials said. The attacker was reported to be a member of the provincial governor’s security team.

Several current and former officials lamented the death of Abdul Raziq, 39, a close U.S. ally and fierce anti-Taliban fighter.

“It is a big loss for Afghanistan,” Shakeba Hashimi, a legislator from Kandahar, said by cellphone as she was en route to his funeral. “We have security in Kandahar that we don’t have in the capital. It is because of this honorable general.”

Amrulleh Saleh, a former Afghan national intelligence chief, tweeted that Abdul Raziq had been “an architect of stability” in Kandahar and had established “deep political networks” in support of the government.

“This is a pan-Afghan loss,” he wrote.

Afghanistan’s ambassador to Pakistan, Omar Zakhilwal, tweet­ed that Abdul Raziq’s death was “a dark day” for the country and that he was “shocked and heartbroken by the demise of close friend, great patriot & national hero.”

He said Abdul Raziq had “single-handedly restored stability to a volatile Kandahar and the greater south.”

Abdul Raziq, a lieutenant general in the Afghan National Police, was a controversial official who had been repeatedly accused of complicity in severe human rights abuses during his rise to power in Kandahar, birthplace of the Taliban militancy — allegations he denied.

Nonetheless, he earned a reputation as a ferocious opponent of the Taliban and gained the respect of successive American and NATO military officials in Afghanistan.

He had survived a number of assassination attempts, including suicide attacks.

A slight and youthful-looking man, Abdul Raziq earned a reputation for brutality and corruption in the border police beginning a decade ago. But in recent years, as a top police official and ruthless anti-insurgent fighter, he was widely praised for bringing Kandahar and the surrounding region under government control. His forces received Western training and funds, and U.S. military officials often consulted him.

Last year, a United Nations report said the worst torture in Afghanistan took place in police jails in Kandahar, and the U.N. Committee Against Torture called for the investigation and prosecution of Abdul Raziq. A decade earlier, a 2006 U.S. State Department study alleged that he had been removed from his post with the border police for arresting and tormenting a group of men from a rival clan. He categorically denied any wrongdoing.

Miller, 57, took over last month as the top U.S. commander in Afghanistan, replacing Gen. John W. Nicholson Jr. A veteran of some of the U.S. military’s most secretive combat units, Miller formerly led the U.S. Joint Special Operations Command and participated in numerous combat operations in Iraq and Afghanistan and, in 1993, in Mogadishu, Somalia.

Thursday’s brazen attack followed a spate of insurgent and political violence during the run-up to Saturday’s parliamentary elections. The Taliban has threatened to “severely disrupt” the elections and warned Afghans against participating in what the radical Islamist group regards as a pretext for perpetuating U.S. intervention in the country.

The Taliban warned students and teachers in particular to stay away from voting places, many of which are in schools. But the group said it would seek to avoid harm to civilians.

The attack in Kandahar narrowly targeted senior U.S. and Afghan security officials, as well as the provincial governor and intelligence chief. The lone attacker reportedly opened fire at close range as those officials were finishing their meeting.

But the lethal shooting seemed likely to have a chilling effect on voter participation Saturday, especially in the south, where several candidates have been assassinated.

On Wednesday, a prominent candidate, former army general Abdul Jabar Qahraman, was killed in neighboring Helmand province by a hidden bomb that exploded while he was holding a meeting at his campaign headquarters in the provincial capital, Lashkar Gah. Qahraman, an ardent opponent of the Taliban, was the 10th candidate killed in the past two months.

In a suicide attack Wednesday near the largest U.S. military base in Afghanistan, a bomber killed two Afghan civilians and wounded at least five Czech soldiers belonging to the U.S.-led NATO coalition in the country, officials said. The Taliban claimed responsibility for the bombing near Bagram air base, about 30 miles north of the capital, Kabul.