A bungling robber shot his accomplice in the leg during an attempted armed raid at a flat.

Keith Smith, 30, and Peter McMurray, 25, pleaded guilty to trying to rob Ekundayo Badamas in Cables Wynd in Edinburgh on August 26 this year.

Advocate depute Keith O'Mahony, told judge Lord Beckett at the High Court in Edinburgh that at about 11pm Mr Badamas heard a knock on the front door.

When he opened it, he was confronted by McMurray, who was holding a knife, and Smith. A struggle broke out and the victim was struck with the blade.

Smith then took a rifle from a bag he was carrying and fired once, unwittingly shooting McMurray in the leg.

The court was told the gun had been fired as "an attempted warning shot".

Mr Badamas managed to force the men out of the house.

On their way out Smith put the rifle back into the bag but did not engage the safety catch and while running down the staircase the gun discharged in the bag.

The bullet became embedded in a fire door. Neighbours had contacted the police because of the noise coming from the flat.

Smith was seen on CCTV running towards Sheriff Brae with the holdall and shortly thereafter running back again without it and going into The Shore pub.

He appeared panicked, was sweating and was on his phone to a taxi company saying he had to go to accident and emergency.

Meanwhile, the police found McMurray lying on the pavement about 30 yards from the flat.

He had a significant injury to his lower left leg and told the officers a white car had drawn up and someone had shot him.

Smith was arrested by armed police officers on August 31 and he told them: "I knew you guys would be coming for me. I wasn't surprised to see the police with guns".

McMurray was taken to Edinburgh Royal Infirmary where it was found the bullet had fractured his left tibia and he required several "washout" operations to remove bullet fragments and had a pin inserted into his leg.

He was discharged on September 3 and detained. He appeared in court on crutches. Mr O'Mahony said the firearm was a German Walther .22 self-loading rifle.

Tests found the minimum trigger pressure required to discharge it was only half of that normally expected. The knife had a 280mm blade.

Mr Badamas, 50, required 14 stitches to the left hand side of his forehead and will be left with permanent scarring. Smith has seven previous convictions, including one for assault to danger of life.

McMurray has six previous convictions, including assault to severe injury, permanent disfigurement and permanent impairment.

Lord Beckett told the pair: "I consider this very grave criminality. You armed yourselves with a rifle and a very large knife and attempted to commit a robbery in the course of which the complainer was injured and will have permanent disfigurement".

He added he would consider how best to protect the public and was proposing an extended sentence.

Lord Beckett deferred sentence on the men until December 7 for a criminal social justice report.