At least two US Marines were killed in the strike on the base in Helmand province, which houses American and British troops among others.
According to The New York Times, the base, Camp Bastion, is where Prince Harry is serving as a member of a British helicopter unit. Prince Harry was not in any danger, said the spokesman, Master Sgt. Bob Barko.
It was not clear whether the attack was meant to be an attempt on the prince’s life, Sergeant Barko said. The Taliban have earlier vowed to kill him.
Major Adam Wojack, a spokesman for International Security Assistance Force in Kabul, confirmed British forces had been involved in repelling the attack, alongside American troops.
A spokesman for the Ministry of Defence in London said: “After swift action by ISAF forces, which included UK personnel, the incident was contained.” It is understood that the British troops were directly involved in the exchanges of fire.
The prince, an army captain who was deployed recently, is based at Camp Bastion for his second tour of duty.
Harry was about two kilometres away with other crew members of the Apache attack helicopters, of which he is a co-pilot gunner, when the attack took place, sources told Guardian.
A Taliban commander said that Harry was the main focus of the attack, but other Taliban spokesmen told media organisations that the attack was in revenge for the anti-Islamic film The Innocence of Muslims.
The fighting broke out after protests swept the Middle East over an amateur film that mocked Islam. Western embassies in Libya, Egypt and Sudan were among those that were raided and looted.
A Ministry of Defence source said: “After saying this attack was mounted in reaction to the video on Islam, it is entirely predictable that the Taliban have changed their tune to say it was aimed at Captain Wales.
“The insurgency who mounted this attack – most of who were killed by Isaf – were nowhere near Captain Wales, who with other UK and Isaf personnel was under lockdown.”
Major Martyn Crighton, from Isaf, said: “Nobody would deny that the insurgents are opportunistic. Isaf’s facilities are very safe places, it just so happens that last night insurgents were able to make a spectacle of themselves and cause some damage.
“But there wasn’t any real threat that it was under attack from a large group of insurgents.”
The Taliban dismissed Harry’s role as a propaganda stunt and claimed he was there to “atone” for the embarrassment caused by leaked pictures of him naked in a Las Vegas hotel room.
Zabiullah Mujahid, a spokesman for the insurgents, said: “The British Army is under pressure, just like the other forces in Afghanistan, and Britain wants to encourage its soldiers with such actions.
“And also the Prince was seen in naked pictures in England. To cover this shame, maybe he can atone by showing that he is fighting beside their soldiers in Afghanistan.”
“The British haven’t been able to do anything here in Afghanistan with all their soldiers. They can’t do anything with their Prince here either,” Mujahid added.
Camp Bastion is a huge base in the middle of the desert and is shared with US, Estonian, Danish and Afghan troops.