Three American service members and a US contractor were killed after their convoy was hit by a roadside bomb near the main US base in Afghanistan.

The Taliban claimed responsibility for the attack.

The US and Nato said the four Americans were killed in the explosion near Bagram Air Base, north of Kabul, while three other people were wounded.

The base in Bagram district is located in northern Parwan province and serves as the main US air facility in the country.

The wounded were evacuated and are receiving medical care, the statement said. The names of service members killed in action are being withheld until their next of kin have been notified.

The Taliban said it had launched the attack, with one of its suicide bombers detonating his explosives-laden vehicle near the Nato base. The conflicting accounts of the attack could not be immediately reconciled.

Read more: Outrage as school pupils killed by Saudi-led air strike

On Tuesday, local officials said at least five Afghan civilians were wounded in the commotion after the attack on the American convoy. Four were passers-by and the fifth was a driver of a car going down the road, said Abdul Raqib Kohistani, the Bagram district police chief.

Abdul Shakor Qudosi, the district administrative chief in Bagram, said American soldiers opened fire immediately after their convoy was bombed.

Monday's US fatalities bring to seven the number of US soldiers killed so far this year in Afghanistan, underlining the difficulties in bringing peace to the war-torn country even as Washington has stepped up efforts to find a way to end the 17-year conflict, the longest in American history.

There are about 14,000 US personnel in Afghanistan, supporting Afghan forces as they struggle on two fronts - facing a resurgent Taliban who now hold sway over almost half the country and also the Islamic State affiliate, which has sought to expand its footprint in Afghanistan even as its self-proclaimed "caliphate" has crumbled in Syria and Iraq.

Last year, 13 US service members were killed in Afghanistan.

The Taliban have continued to carry out daily attacks on Afghan security forces despite holding several rounds of peace talks with the United States in recent months. The Taliban have refused to meet with the Afghan government, which they view as a US puppet.

Meanwhile, the Taliban have agreed to take part in an all-Afghan gathering later this month in Qatar, where the insurgents maintain a political office.

But the Taliban said they will not recognise any government official attending the gathering as a representative of the Kabul government, only as an individual Afghan participant.