A U.S. computer hacker who wormed into the files of thousands of corporations will be released from prison on time served after helping the FBI thwart hundreds of cyberattacks on government.

Hector Xavier Monsegur, a Puerto Rican from Manhattan who used the alias Sabu, faced 20 years in prison after being arrested in 2011 on charges of hacking the computer systems of Fox television, Nintendo, PayPal and other businesses.

Prosecutors asked a New York judge for leniency for Monsegur ahead of his sentencing hearing Tuesday because of the high level of co-operation they had from him. The judge sentenced him to the seven months behind bars he has already served.

Monsegur is credited with helping the U.S. government disrupt hundreds of cyberattacks on Congress, NASA and other sensitive targets and saving millions of dollars.

Monsegur "provided, in real time, information about then-ongoing computer hacks and vulnerabilities in significant computer systems," prosecutors wrote.

The FBI estimates he helped detect at least 300 separate hacks and crippled the group of so-called hacktivists known as Anonymous.

At least five arrests are connected to his efforts to expose fellow hackers. Among those he helped trap was Jeremy Hammond, the FBI's most wanted cybercriminal whose stated objective was to cause mayhem, prosecutors said.

Monsegur and his family had to be relocated because of death threats after Sabu was vilified online.

Court papers say Monsegur first began hacking in a Manhattan apartment in the early 2000s, stealing credit card information to pay his bills. Now 30, he was then unemployed and trying to care for two foster children, whose mother was in jail.

Monsegur, who had not completed high school, led a group of hackers called LulzSec which hacked into corporate security systems, stole information and bragged about it online.

Monsegur said he was motivated by the case of WikiLeaks founder Julian Assange, who released thousands of internal government documents.

"I'm just doing what I know how to do, and that is counter abuse," Monsegur said.

When the FBI tracked him down in 2011, he immediately agreed to share his hacker secrets to help reinforce government security systems.