Heavy street fighting between militants and security forces in the centre of the Afghan capital, Kabul, ended on Monday after 18 hours of gunfire, rocket attacks and explosions, police and government officials said.

Battles which broke out at mid-day on Sunday gripped the city's central districts through the night, with explosions and gunfire lighting up alleys and streets.

The Afghan Defence Ministry said 32 insurgents were killed in the attacks which paralysed Kabul's government district, and which targeted three other provinces in what the Taliban called the start of a spring offensive. One fighter was captured.

In only a short time we managed to cut short their devilish plans and all 32 insurgents were killed. They carried suicide vests, but managed to do nothing except be killed, Defence Ministry Chief of Operations Afzal Aman said.

Nevertheless, the assault highlighted the ability of militants to strike at high-profile targets in the heart of the city even after more than 10 years of war.

The attacks also represented another election-year setback in Afghanistan for U.S. President Barack Obama, who wants to present the campaign against the Taliban as a success before the departure of most foreign combat troops by the end of 2014.

Four insurgents died attacking the Afghan parliament, while six were killed in a multi-story building under construction that they had occupied to fire rocket-propelled grenades and rifles down on the heavily fortified diplomatic enclave.

Four were killed in Kabul's east, Aman said, while nine died attacking a NATO base in the eastern city of Jalalabad.

Three Afghan soldiers were killed and 10 wounded in the fighting, and only ended with special force assaults mounted as dawn broke. Eight policemen were killed and 36 wounded in the clashes in Kabul and the provinces.

NATO helicopters had launched strafing attacks on gunmen in the building site, which overlooked the NATO headquarters and several embassies, including the British and German missions.

Elite soldiers scaled scaffolding to outflank the insurgents, who took up defensive positions on the upper floor of the half-built building. Bullets ricocheted off walls, sending up puffs of brick dust.

I could not sleep because of all this gunfire now. It's been the whole night, said resident Hamdullah.

The assault, which began with attacks on embassies, a supermarket, a hotel and the parliament, was one of the most serious on the capital since U.S.-backed Afghan forces removed the Taliban from power in 2001.

Afghan President Hamid Karzai was yet to make a statement after being locked down by guards at his walled presidential place compound as the attacks broke out.

STRIKE ON THE DIPLOMATIC ZONE

The Taliban claimed responsibility, but some officials said the Haqqanis, a network of ethnic Pashtun tribal militants allied with the Taliban, who live along the Pakistan-Afghanistan border, were likely involved.

My guess, based on previous experience here, is this is a set of Haqqani network operations out of North Waziristan and the Pakistani tribal areas, American Ambassador Ryan Crocker told CNN.

North Waziristan, in Pakistan, is a notorious militant hub.

Frankly I don't think the Taliban is good enough, Crocker said.

Taliban spokesman Zabihullah Mujahid said the assaults in Kabul and three eastern provinces marked the beginning of a new warm-weather fighting season.

These attacks are the beginning of the spring offensive and we had planned them for months, Mujahid told Reuters.

He said the onslaught was revenge for a series of incidents involving U.S. troops in Afghanistan - including the burning of Korans at a NATO base and the massacre of 17 civilians by a U.S. soldier - and vowed there would be more.

The Taliban said on Sunday the main targets were the German and British embassies and the headquarters of the NATO-led force. Several Afghan members of parliament joined security forces repelling attackers from a roof near parliament.

The attacks come a month before a NATO summit at which the United States and its allies are supposed to put finishing touches on plans for the transition to Afghan security control, and days before a meeting of defence and foreign ministers in Brussels to prepare for the alliance summit in Chicago.

Western combat forces are due to leave Afghanistan by 2014, under a plan to hand over responsibilities to Afghan forces.

But the Afghan security forces are plagued by poor discipline and they apparently failed to learn lessons from a similar assault in Kabul last September, when insurgents took up position in a tall building under construction to embassies and NATO offices below.

On Sunday, the insurgents fired from behind green protective netting wrapped around the skeleton of the building under construction over-looking the diplomatic quarter.

Hours earlier in neighbouring Pakistan, dozens of Islamist militants had stormed a prison in the dead of night and freed nearly 400 inmates, including one on death row for trying to assassinate former President Pervez Musharraf.

(Editing by Robert Birsel)