A student who hacked into Facebook in "the most extensive and grave" case of social media hacking ever to come before a British court has been sentenced to eight months in prison.

Glenn Mangham, 26, admitted to infiltrating the website from his bedroom in his parents' house last year, sparking fears by US authorities that Facebook was the target of industrial espionage.

Prosecutors said that he stole "invaluable" intellectual property after hacking into the account of a Facebook employee who was on holiday, and through it obtained restricted internal data.

Mangham, a software development student from Cornlands Road, York, claimed that he had previously shown the search engine Yahoo how it could improve its security and said he wanted to do the same for Facebook.

But this was rejected by the prosecutor, Sandip Patel, who told Southwark crown court in London: "He acted with determination and undoubted ingenuity and it was sophisticated, it was calculating. This represents the most extensive and grave incident of social media hacking to be brought before the British courts."

He said that Mangham had ultimately stolen "invaluable" intellectual property, which he downloaded on to an external hard drive during the period of hacking in April to May last year.

Facebook discovered the breach in May and alerted the FBI, while Scotland Yard's e-crimes unit raided Mangham's home on 2 June 2011 following what Patel described as a "concerted, time-consuming and costly investigation".

Explaining his actions, Mangham told the court: "It was to identify vulnerabilities in the system so I could compile a report that I could then bundle over to Facebook and show them what was wrong with their system."

Tony Ventham, defending, said Mangham was an "ethical hacker" who described himself as a security consultant and told the court: "He saw this as a challenge. This is someone who in previous times would have thrown everything aside to seek the source of the Nile."

He added: "It was common currency within the community of computer nerds or geeks, if I may refer to him as that, where there was this interesting relationship between companies and people who ethically point out vulnerabilities."

The court was also told that Mangham was of good character but showed strong indications of Asperger's syndrome, and may have been trying to prove himself to his father, who works in the computer industry.

Judge McCreath told him that he was bearing in mind the fact that Mangham had never been in trouble before, as well as his youth, and his "psychological and personal make-up".

"I acknowledge also that you never intended to pass any information you got through these criminal offences to anyone else and you never did so, and I acknowledge that you never intended to make any financial gain for yourself from these offences.

"But this was not just a bit of harmless experimentation. You accessed the very heart of the system of an international business of massive size, so this was not just fiddling about in the business records of some tiny business of no great importance."

He described Mangham's actions as "persistent conduct, sophisticated conduct and conduct that had at least the risk of putting in danger the reputation of an innocent employee of Facebook".

Mangham's claim that he had always intended to alert the website to what he had done was a retrospective justification, rather than his motivation, he added.

The student was also given a serious crime prevention order restricting his access to the internet and confiscating his computer equipment.

Alison Saunders, chief crown prosecutor for CPS London, said: "This was the most extensive and flagrant incidence of social media hacking to be brought before British courts."

Facebook said in a statement that it applauded police and prosecutors' efforts in the case, adding: "We take any attempt to gain unauthorized access to our network very seriously."