Two British servicemen were shot dead minutes after their suspected killers, two rogue Afghan police officers, casually posed for photographs, an inquest has heard.

Corporal Brent McCarthy, 25, and Lance Corporal Lee Davies, 27, were helping to train and mentor members of the Afghan police as part of the handover of security responsibilities when they were attacked.

Just moments earlier the soldiers had taken photos of the two young men blamed for the attack. In one they posed with their AK-47 rifles; in another image one of the suspects is pictured alongside McCarthy, an RAF policeman.

McCarthy and Davies, a member of 1st Battalion Welsh Guards, had gone to visit an Afghan police headquarters in the Lashkar Gah district of Helmand province. The British men were part of a patrol that had turned up unannounced at the base so they could quiz a police commander about a tip-off that one of his colleagues was working with the Taliban.

Shortly after their arrival, a short burst of gunfire left the pair fatally wounded. The two suspected killers were seen running out the base's main gate and across fields by another British soldier. One of them, believed to be only 18 or 19, was later killed.

Guardsman Joshua Foley, who witnessed the attack, said the British troops generally had "a good relationship" with the Afghan police.

He said their team had been trained to pick up on warning signs –"atmospherics" – of possible attacks by Afghan security forces but that day, Saturday 12 May last year, "the atmospherics were fine".

Foley said as he stood with Davies and McCarthy near the main gate, two Afghan policemen passed them and there was an attempt by the British soldiers to strike up some banter.

"We tried to have a laugh with them but they didn't seem to get it," Foley told the court. McCarthy then produced a camera and the Afghans agreed to have some photos taken.

Foley left Davies and McCarthy with the policemen to take up duty in one of the base's two guard towers. He said that when he left the two men their weapons were on a concrete slab next to them but within reach.

He said: "I heard a rapid burst of shots, and as I looked I saw the two Afghan police holding their weapons. I did not see the Afghan police fire any shots but they both ran out of the main entrance." Foley told the inquest the men he saw running away were the same two who had posed for photos. The two injured soldiers were evacuated but could not be saved. The identity of the suspected attackers is not known.

The inquest continues.