Taliban fighters on Saturday battled a local militia in northern Afghanistan in some of the first significant armed clashes since the group’s rapid takeover of the country, while the Islamist group’s political leaders held talks in Kabul on the formation of a new government.

Efforts to evacuate foreign nationals and Afghans who have worked with them over the past two decades, meanwhile, continued to be plagued by chaotic conditions in the capital. Taliban checkpoints and unruly crowds prevented many from reaching the airport.

The U.S. embassy warned Americans that “because of potential security threats outside the gates at the Kabul airport, we are advising U.S. citizens to avoid traveling to the airport and to avoid airport gates at this time.”

A Taliban flag flew earlier this month in Baghlan province. A local militia attacked Taliban forces Friday, and fighting continued Saturday.

Photo: -/Agence France-Presse/Getty Images

President Biden on Friday vowed to evacuate any American who wanted to leave the country, and said the U.S. would also work to extract Afghan translators and other allies of the U.S., calling the mission dangerous.

“I cannot promise what the final outcome will be or that it will be without risk of loss, but as commander in chief, I can assure you that I will mobilize every resource necessary,” he said.

Members of a local militia in the northern province of Baghlan province attacked Taliban forces on Friday, and fighting continued Saturday, both sides said.

Pictures and video posted on social media showed anti-Taliban militia fighters celebrating capturing some government buildings in Baghlan, along with military and police vehicles. The militia said, in social media posts, that it had killed some Taliban fighters.

Three districts in the Baghlan province are now under the militia’s control, said Ahmad Yasin Zia, who stepped down as the Afghan army’s chief of staff earlier this year and has left the country.

A Taliban official said the militia had captured some territory, terming it a “distraction” as the group prepares to declare a new national government with itself in charge.

The Taliban raced through the country in a lightning campaign, which started in May, seizing control without much of a fight as the Afghan national army melted away.

The fighting on Friday and Saturday occurred adjacent to the Panjshir Valley, populated by members of the country’s Tajik ethnic minority, which held out against Taliban rule in the 1990s. That area is now the base of a new group that has pledged to block any incursion by the Taliban.

Chaotic conditions at Kabul’s airport are hindering evacuation efforts.

Photo: Anadolu Agency via Getty Images

Calling themselves the National Resistance Front, leaders of the group said they have assembled a force of more than 7,000 men. Ali Nazary, the group’s head of foreign affairs, said that number includes a substantial number of officers from the Afghan security forces.

Mr. Nazary said the group also has some helicopters from the Afghan air force. He said the group’s plan was to defend the valley in the event of a Taliban attack. He said the militia in Baghlan had acted independently.

“We’re not going to let invaders take over this valley, which has never been conquered,” said Mr. Nazary. He said the group was willing to accept peaceful coexistence with the Taliban if it respects human rights and decentralizes power to the provinces.

The Taliban’s political chief, Mullah Abdul Ghani Baradar, arrived in Kabul this week. The Taliban, which says it wants to establish an inclusive government, has held talks in recent days with leading Afghan politicians including former president Hamid Karzai and former chief peace negotiator Dr. Abdullah Abdullah.

Write to Saeed Shah at saeed.shah@wsj.com and Jessica Donati at jessica.donati@wsj.com