A software engineer who bought a gun and silencer online was jailed for five years after law enforcement forces in Scotland and America co-operated to thwart his plan.

David Mitchell purchased the gun and 150 rounds of ammunition after searching on the dark web but ended taking delivery of a package mocked up to look like the original after US Homeland Security intervened.

A Homeland Security special agent intercepted the original parcel at Newark airport in the USA on September 17 last year which was addressed to Pitreavie Court in Dunfermline, Fife.

It was found to contain an amplifier but hidden inside the item was a fully operational Glock handgun, a sound suppressor and bullets.

A judge told Mitchell: "These offences arose from your planned and deliberate conduct in attempting to acquire a working Glock pistol and a quantity of suitable ammunition.

"It appears you formed a plan to obtain these items by carrying out research on the dark web," said Lord Pentland.

Advocate depute Liam Ewing earlier told the court that following the find a joint operation was set up between Police Scotland and the National Crime Agency to create a package containing metal and wood to mock up the original.

Mitchell was put under surveillance and a cardboard box containing the placebo was delivered to his workplace in Dunfermline.

Mr Ewing said: "The accused was seen signing for and taking delivery of the package.

"Later that day the accused was observed exiting the premises and placing the box in his car before driving home."

Firearms officers later turned up at Mitchell's home in Damside, in Edinburgh.

He told them: "There is something under the chair in the living room and something in the recycling bin in the kitchen

"The mocked up package was discovered under the chair and the amplifier and packaging were in a recycling box.

Mitchell, 48, was told a search would be carried out at his workplace but he said: "There's nothing there anyway."

The prosecutor said Mitchell 'appeared distant' and was staring into space.

He said he suffered from depression and took medication for the condition.

Mr Ewing said officers were concerned about Mitchell's mental health and arranged a medical examination.

A psychiatrist confirmed that he was fit to be interviewed.

The pistol, silencer and bullets found at Newark airport, in New Jersey, were sent to Scotland to be examined by ballistics experts.

The gun was found to be in working order but the silencer was not suitable for use with the Glock.

Mitchell, a prisoner in Perth, admitted purchasing and attempting to possess the pistol, silencer and ammunition between September 17 and 19 this year and attempting to possess a prohibited firearm.