Explosions and gunfire were exchanged near Kabul International Airport on Thursday. Attacks began after dawn when militants occupied a building north of the airport, but Afghan forces quickly responded. (Reuters)

Afghan election officials on Thursday began a nationwide recount of ballots casts in last month’s disputed presidential runoff vote, just hours after Taliban insurgents staged a predawn attack on Kabul International Airport.

The raid by four gunmen, one of the most brazen militant assaults in recent months, underscored Afghanistan’s mounting political and security woes as foreign troops prepare to withdraw by the end of the year.

For weeks, the political crisis stemming from the dispute over the results of the June 15 runoff threatened to destabilize Afghanistan, with one candidate nearly declaring a breakaway government.

Meanwhile, security forces continue to battle the Taliban-led insurgency in many parts of the country. On Thursday, at least a dozen explosions and heavy gunfire pierced the predawn calm in Kabul about 4:30, as insurgents fired rocket-propelled grenades at the airport from a building about a mile away, security officials said.

Fighter jets swooped over the city as Afghan forces fought and eventually killed the militants in a four-hour gun battle. No other deaths were reported.

Also in the capital, the Independent Election Commission (IEC) announced that it had started inspecting votes from the June 15 poll, which election officials acknowledged was marred by widespread fraud. The U.N.-supervised audit of 8 million ballots will take three to four weeks and involve hundreds of staff members working 12-hour shifts, IEC Chairman Ahmad Yusuf Nuristani said Thursday.

Abdullah Abdullah, a former foreign minister and aide to legendary Northern Alliance commander Ahmed Shah Massoud, had accused the commission of helping rig the vote for his opponent, former finance minister and World Bank executive Ashraf Ghani.

When the IEC released preliminary results last week that showed Ghani with 56 percent of the vote, Abdullah cried foul, and some of his most powerful supporters warned that they might declare a parallel cabinet. Ghani finished second to Abdullah in the first round of voting, on April 5, but Abdullah fell short of a majority, necessitating the runoff.

Abdullah’s campaign spokesman said that 30 ballot boxes were “symbolically recounted” Thursday but that the full audit did not immediately start. Nuristani said earlier that international observers had not yet arrived in Kabul to monitor the full recount.

The presidential election was supposed to mark Afghanistan’s first democratic transfer of power. But the dispute over the runoff results challenged that endeavor. In a last-minute effort to stave off the potential collapse of the Afghan state, the White House dispatched Secretary of State John F. Kerry to help resolve the impasse.

The two sides reached a vague agreement Saturday that reportedly outlined the principles of the audit and a more general framework for a national consensus government after the new results are announced. Kerry was instrumental in leading the negotiations.

But soon afterward, officials from both campaigns said there were disagreements over whether the IEC or an international institution such as the United Nations would be in charge of the recount, suggesting that the accord was already in trouble.

A senior U.S. official said Monday, however, that the IEC will technically conduct the audit, although “it’s being done under the auspices of and the supervision by the U.N.”

The rival campaigns had been tasked with nominating a new IEC chief executive under the deal. But speaking at a news conference Thursday, Abdullah said they had agreed to appoint two people from each side to jointly manage the IEC.

“It would have taken too much time to find a person” trusted by both sides to honestly run the audit, Abdullah said.

He said the two teams maintained a spirit of cooperation. “While the audit has begun, there are serious questions about the implementation,” he said. He did not elaborate, but said that discussions are ongoing and that the two teams are in “good spirits.”

According to one of Abdullah’s two vice presidential picks, Mohammad Mohaqiq, the candidate with the fewest votes after the recount will become “chief executive” of the government, a post that eventually will transition to that of prime minister.

Such an arrangement would upend Afghanistan’s highly centralized presidential system, but it would pave the way for a more even distribution of power, U.S. officials said.

Also Thursday, Taliban militants ambushed a convoy of President Hamid Karzai’s palace guard in the eastern province of Paktia, wounding four. Karzai had been scheduled to visit the nearby province of Paktika to honor the victims of a deadly car bombing this week.

Sayed Salahuddin contributed to this report.