Three British soldiers have been killed and four injured by a renegade Afghan soldier in Afghanistan, the Ministry of Defence said.

The men, from 1st Battalion The Royal Gurkha Rifles, were on duty on Tuesday morning in Nahr-e Saraj, Helmand province, when the Afghan opened fire.

One is believed to be a Nepalese Gurkha and the other two were UK nationals.

Prime Minister David Cameron condemned the "appalling" killings, but said UK and Afghan troops should work together.

The Taliban has claimed the Afghan soldier had joined its insurgency.

An investigation is under way and next of kin have been informed.

Meanwhile, in a separate incident a Royal Marine from 40 Commando was killed in Helmand, the MoD said. Family have been told.

He was shot dead on Tuesday while on foot patrol in the Sangin district.

The number of British military personnel killed on operations in Afghanistan since 2001 now stands at 318.

Mr Cameron said the current strategy of working alongside local security forces should go on.

"It is absolutely essential that we don't let this terrible incident change our strategy. It is the right thing to do to build up the Afghan national army," he said.

He went on: "We need to make sure that we build up that army because that, in the end, is the way that we are going to be able to bring our troops back home."

Similarly, Defence Secretary Liam Fox said: "Training and developing the Afghan National Security Forces is vital to the international mission in Afghanistan and today's events will not undermine the real progress we continue to make. British and Isaf forces are working shoulder to shoulder with Afghans and will continue to do so undeterred."

Afghan President Hamid Karzai has apologised to the UK after the incident and a defence ministry spokesman said a soldier from the Afghan National Army (ANA) was being sought.

Analysis This is not the first time this kind of incident has happened. Last November a member of the Afghan National Police opened fire on British soldiers he was serving alongside. He killed five and seriously injured half a dozen others. But the Ministry of Defence is anxious to highlight how rare these kinds of incidents are. Since 2006, British forces have trained 130,000 Afghan troops. Some 5,000 of the 10,000 British servicemen currently deployed in Afghanistan are working alongside members of the Afghan Security forces day in and day out. The training and mentoring of Afghanistan's army and police is essential to the goal of eventually leaving an Afghanistan capable of looking after its own security. That is why Liam Fox is stressing that, despite this tragedy, British forces will "continue to work shoulder to shoulder with the Afghans" and will not be deterred. Royal Marine dies in Afghanistan

Mr Cameron said he spoke to President Karzai on Tuesday morning and both men agreed that an urgent investigation was required.

President Karzai's spokesman, Waheed Omar, said the Afghanistan government was also investigating the killings and the government would "do everything to ensure the perpetrators are brought to justice".

The BBC understands that one of the soldiers killed was shot and the other two were killed by a rocket-propelled grenade.

There is a helpline number in the UK for concerned relatives - 08457 800900.

The spokesman for Task Force Helmand, Lt Col James Carr-Smith, said: "We believe these were the actions of a lone individual who has betrayed his Isaf and Afghan comrades.

"His whereabouts are currently unknown but we are making strenuous efforts to find him. He should know that his actions will not deter us from our task and we will continue to work closely with our Afghan friends to bring security to Helmand.

"Three courageous and dedicated soldiers have made the ultimate sacrifice. They will be greatly missed and their actions will not be forgotten. We will remember them."

British soldiers in Afghanistan have trained 130,000 Afghan troops since 2006, and 5,000 British troops are currently partnering members of the ANA.

It appears to be the third incident in which a member of the Afghan security forces has opened fire on British troops.

We have sacrificed greatly together and we must ensure the trust between our forces remains solid in order to defeat our common enemies Gen David Petraeus, NATO commander, Afghanistan Reaction to deaths of UK soldiers

There was one incident in 2008 when two British soldiers were shot in the leg, and another in November 2009 when five British soldiers were shot dead by an Afghan policeman.

Security correspondent Frank Gardner said he was not surprised that the attack had happened because the vetting process to join the Afghan military is poor. It is not a popular career move, he said, because it is poorly paid and dangerous.

"It is important to keep an open mind about what has motivated this person," said our correspondent.

"This kind of thing often has rather more below the surface. There are often tribal feuds, there are family feuds; there are personal reasons. So it isn't always down to the insurgency."

Our correspondent added that the tragedy was likely to intensify debate over the human costs of the mission in Afghanistan, but he said the West's exit strategy relies on training the Afghan security forces.

The Nato commander in Afghanistan, Gen David Petraeus, said: "This is a combined joint mission - Afghan and Alliance troopers fighting shoulder to shoulder against the Taliban and other extremists.

"We have sacrificed greatly together and we must ensure the trust between our forces remains solid in order to defeat our common enemies."

And Col Richard Kemp, a former commander of British troops in Afghanistan, told the BBC it was important to remember that this was an isolated incident and "not a pattern of events".