KABUL, AFGHANISTAN -- The Taliban on Saturday captured a large, heavily defended city in northern Afghanistan in a major setback for the government, and were approaching the capital of Kabul, less than three weeks before the U.S. hopes to complete its troop withdrawal.

The fall of Mazar-e-Sharif, the country's fourth largest city, which Afghan forces and two powerful former warlords had pledged to defend, hands the insurgents control over all of northern Afghanistan, confining the Western-backed government to the center and east.

Abas Ebrahimzada, a lawmaker from the Balkh province where the city is located, said the national army surrendered first, which prompted pro-government militias and other forces to lose morale and give up in the face of a Taliban onslaught launched earlier Saturday.

Ebrahimzada said Abdul Rashid Dostum and Ata Mohammad Noor, former warlords who command thousands of fighters, had fled the province and their whereabouts were unknown.

Noor said in a Facebook post that his defeat in Mazar-e-Sharif was orchestrated and blamed the government forces, saying they handed their weapons and equipment to the Taliban. He did not say who was behind the conspiracy, nor offer details, but said he and Dostum "are in a safe place now"

The Taliban have made major advances in recent days, including capturing Herat and Kandahar, the country's second- and third-largest cities. They now control about 24 of Afghanistan's 34 provinces, leaving the Western-backed government with a smattering of provinces in the center and east, as well as the capital, Kabul.

On Saturday, the Taliban captured all of Logar province, just south of Kabul, and detained local officials, said Hoda Ahmadi, a lawmaker from the province. She said the Taliban have reached the Char Asyab district, just 11 kilometers (7 miles) south of the capital.

Later, the insurgents took over Mihterlam, the capital of Laghman province, northeast of Kabul, without a fight, according to Zefon Safi, a lawmaker from the province.

On Saturday, Afghan President Ashraf Ghani delivered a televised speech, his first public appearance since the recent Taliban gains. He vowed not to give up the "achievements" of the 20 years since the U.S. toppled the Taliban after the 9/11 attacks.

The U.S. has continued holding peace talks between the government and the Taliban in Qatar this week, and the international community has warned that a Taliban government brought about by force would be shunned. But the insurgents appear to have little interest in making concessions as they rack up victories on the battlefield.

"We have started consultations, inside the government with elders and political leaders, representatives of different levels of the community as well as our international allies," Ghani said. "Soon the results will be shared with you," he added, without elaborating further.

Hours later, his forces suffered one of the biggest setbacks since the Taliban offensive began.

Mazar-e-Sharif, home to a famous blue-tiled Muslim shrine, was a stronghold of the Northern Alliance, ethnic militias who helped the U.S. topple the Taliban in 2001.

In 1997, as many as 2,000 Taliban fighters were captured and killed by forces loyal to Mohammed Mohaqiq, a Shiite Hazara leader, and his ethnic Uzbek allies. The following year, the Taliban returned and killed thousands of Hazaras in Mazar-e-Sharif in a revenge attack.

Several makeshift camps had sprung up around Mazar-e-Sharif where mostly ethnic Hazaras had taken shelter after fleeing their homes in outlying areas. They said the Taliban had detained relatives who sought to leave their districts and in some cases burned schools.

Tens of thousands of Afghans have fled their homes, with many fearing a return to the Taliban's oppressive rule. The group had previously governed Afghanistan under a harsh version of Islamic law in which women were forbidden to work or attend school, and could not leave their homes without a male relative accompanying them.

Salima Mazari, one of the few female district governors in the country, expressed fears about a Taliban takeover earlier Saturday in an interview from Mazar-e-Sharif, before it fell.

"There will be no place for women," said Mazari, who governs a district of 36,000 people near the northern city. "In the provinces controlled by the Taliban, no women exist there anymore, not even in the cities. They are all imprisoned in their homes."

The Taliban appointed hard-line cleric Mujeeb Rahman Ansari as women's affairs minister in Herat, according to a prominent women's activist from the city who did not want to be identified because she fears for her safety. She described Ansari as being "strongly against women's rights." He rose to prominence about 2015 and became infamous for dozens of billboards he installed in Herat that told women to wear Islamic hijab and demonized those who would promote women's rights.

The Taliban also captured Paktika province and small Kunar province, both bordering Pakistan, as well as Faryab province in the north and the central province of Daykundi, lawmakers from those areas said Saturday.

Sayed Hussan Gerdezi, a lawmaker from Paktia province, said the Taliban seized most of its local capital, Gardez, but battles with government forces were still underway. The Taliban said they controlled the city.

The withdrawal of foreign troops and the swift collapse of Afghanistan's own forces -- despite hundreds of billions of dollars in U.S. aid over the years -- has raised fears the Taliban could return to power or that the country could be shattered by factional fighting, as it was after the Soviet withdrawal in 1989. It's also prompted many American and Afghan veterans of the conflict to question whether two decades of blood and treasure was worth it.

Afghans have been streaming into Kabul's international airport in recent days, desperate to fly out, even as more American troops have arrived to help partially evacuate the U.S. Embassy.

U.S. President Joe Biden has authorized an additional 1,000 U.S. troops for deployment to Afghanistan, according to a statement from a defense official. That raises to roughly 5,000 the number of U.S. troops to ensure what Biden calls an "orderly and safe drawdown" of American and allied personnel. U.S. troops will also help in the evacuation of Afghans who worked with the military during the nearly two-decade war.

The first Marines arrived Friday. The rest are expected by Sunday, and their deployment has raised questions about whether the administration will meet its Aug. 31 withdrawal deadline.

The U.S. Air Force has carried out several airstrikes to aid its Afghan allies on the ground but they appear to have done little to stem the Taliban's advance. A B-52 bomber and other warplanes traversed the country's airspace Saturday, flight-tracking data showed.

The U.S. invaded shortly after the Sept. 11 attacks, which al-Qaida planned and carried out while being sheltered by Taliban. After rapidly ousting the Taliban, the U.S. shifted toward nation-building, hoping to create a modern Afghan state after decades of war and unrest.

Earlier this year, Biden announced a timeline for the withdrawal of all U.S. troops by the end of August. His predecessor, President Donald Trump, had reached an agreement with the Taliban to pave the way for a U.S. pullout.

Biden's announcement set the latest offensive in motion. The Taliban, who have long controlled large parts of the Afghan countryside, moved quickly to seize provincial capitals, border crossings and other key infrastructure.

"The security situation in the city is getting worse," said Kawa Basharat, a resident in Mazar-e-Sharif, hours before the city fell. "I want peace and stability; the fighting should be stopped."

------

Rahim and Akhgar reported from Istanbul and Krauss reported from Jerusalem. Associated Press writers Jon Gambrell in Dubai, United Arab Emirates; Kathy Gannon in Guelph, Ont.; and Robert Burns and Josh Boak in Washington, D.C, contributed to this report.