But Daniel Houghton, 25, will be released almost immediately because he has already served half the term while on remand.
Houghton, a software engineer of Hoxton, east London, pleaded guilty to two offences under the Official Secrets Act at an earlier hearing.
He offered to hand over sensitive computer files containing information about intelligence collection and MI6 staff lists to agents from the Netherlands, the Old Bailey heard.
They at first thought it was a hoax but later tipped off their UK counterparts and Houghton was arrested after arranging a meeting at a London hotel in March.
Mr Justice Bean told him: "The effect on the SIS (Secret Intelligence Service) credibility and the morale of its officers of this kind of act of betrayal is a serious matter."
The judge said he did not know whether it was true, as Houghton claimed, that he was hearing voices that told him to do it but said he was a "strange young man".
The court heard that Houghton, a 23,000 a year software engineer, tried to sell two secret staff lists, one containing the names of 387 individuals and the other with the home and mobile telephone numbers of 39 individuals.
Piers Arnold, prosecuting, said: "It was a personal betrayal of these individuals with the potential if it had fallen into the wrong hands to compromise individuals' safety."
Houghton had worked for the Secret Intelligence Service (SIS), also known as MI6, between September 2007 and May 2009, the court heard.
During this time he accessed "a number of computer files" belonging to the British Security Service (MI5) relating to the work of both intelligence agencies – marked "secret" or "top secret".
They were described as "sensitive capabilities files, important tools developed by SIS staff for the gathering of intelligence for national security purposes".
Mr Arnold said Houghton "dishonestly" removed them from his place of work and in August 2009 tried to sell them to the Dutch Secret Intelligence Service.
After a series of telephone calls it was agreed that he would fly to Holland for a meeting in January this year, at which the Dutch agents were persuaded that he had worked for the SIS as he claimed, and they tipped off MI5.
Houghton later offered to sell the files, plus the staff lists, for 2m, but eventually a fee of 900,000 was agreed upon.
He said that he had copied the material onto a disk which he had taken home and copied in turn onto two memory cards stored at his mother's address.
Houghton handed over the cards to the Dutch at a London hotel on March 1 and was given a suitcase containing 900,000.
In the lobby he was arrested and handcuffed by plain clothes police officers after they wrestled him, struggling, to the floor.
An assessment carried out by SIS found that if the intelligence files he handed over had fallen into the hands of a hostile nation they would have posed "significant risk to future SIS operations", while MI5 faced similar risks.
Copies of the files were also found on a memory card and hard drive at Houghton's home - contradicting his claims to the Dutch agents that there were no other copies of the documents he handed over, Mr Arnold said.
David Perry QC, defending, said: "This was not an offence committed by a calculating ideologue to disclose material to a hostile sovereign state."
He said the Dutch agents contacted by Houghton "at first thought it was a hoax".
"They thought he was either a journalist or a swindler," Mr Perry said.
"The way he was described by one of the Dutch agents was as a naive young man who came across as a loner."
He said the offences were "incompetently executed" and it was clear that Houghton would be caught. Mr Perry said he had used his own phone to approach the Dutch, and he had made no attempt to conceal his identity.