NEW YORK (AP) — A prolific computer hacker who infiltrated the servers of major corporations later switched sides and helped the government disrupt hundreds of cyberattacks on Congress, NASA and other sensitive targets, according to federal prosecutors.

New York prosecutors detailed the cooperation of Hector Xavier Monsegur for the first time in court papers while asking a judge to reward him with leniency at his sentencing Tuesday. They credited Monsegur with helping them cripple Anonymous, the notorious crew of hacktivists who stole confidential information, defaced websites and temporarily put some victims out of business.

Working around the clock with FBI agents at his side, 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, preventing millions of dollars in losses, they added.

After his arrest and guilty plea in 2011, Monsegur faced more than two decades behind bars. But because of his cooperation, the sentence could be two years or less.

Court papers say Monsegur first began hacking in a Manhattan apartment in the early 2000s. His aim then was to steal credit card information, then sell it or use it to pay his own bills.

In a 2011 interview with an online magazine, Monsegur said he decided to join forces with Anonymous because he was upset over the arrest of WikiLeaks founder Julian Assange.

“I’m just doing what I know how to do, and that is counter abuse,” he said.

Starting in early 2011 and using the alias Sabu, Monsegur led an Anonymous splinter group called Lulz Security, or LulzSec, which hacked computer systems of Fox television, Nintendo, PayPal and other businesses, stole private information and then bragged about it online. The group was loosely affiliated with Jeremy Hammond, the FBI’s most wanted cybercriminal whose stated objective was to cause mayhem with the attacks, prosecutors said.

When FBI agents showed up at his home in the summer of 2011, Monsegur immediately agreed to cooperate, giving the FBI a tutorial on the inner-workings and participants of LulzSec and Anonymous, prosecutors said. Under their direction, he “convinced LulzSec members to provide him digital evidence of the hacking activities” and “asked seemingly innocuous questions that … could be used to pinpoint their exact locations and identities,” court papers said.

Monsegur also engaged Hammond in online chats while Hammond was in Chicago, the papers said. As a result, “physical surveillance teams deployed in Chicago, and an electronic surveillance unit in Washington,” they said. Hammond was sentenced last year to 10 years in prison.

Reports that Monsegur was cooperating made him a pariah in the Anonymous movement, prosecutors said. Hackers began posting personal information about him, and he was even approached on the street and threatened, they said.

The harassment “became severe enough that the FBI relocated Monsegur and certain of his family members,” they said.

Monsegur’s current whereabouts aren’t publicly known. One of his attorneys declined to comment Monday.