NEW YORK (Reuters) - A New York hedge fund manager who at age 28 lost nearly all $57 million he oversaw in less than three weeks was spared prison on Monday, as the judge recognized how quickly and thoroughly the defendant owned up to his crimes.

Owen Li, the founder of Canarsie Capital LLC, was sentenced to probation by U.S. District Judge Robert Sweet in Manhattan, prompting gasps from spectators in the courtroom. The defendant then hugged his lawyer, Scott Resnik.

Li, now 30, had pleaded guilty in December to securities fraud and making a false statement.

Sweet had in March indicated he would likely sentence Li to five years in prison, less than federal guidelines advise and in line with prosecutors’ recommendation.

But on Monday, he changed his mind.

“You have done all a human being could do to go take responsibility and to clean up the tragedy,” Sweet told Li. “Perhaps the lesson that comes out of this sentencing should be that there is redemption, and there is grace.”

The judge previously said Li, who attended Stanford University, should also pay $56.8 million of restitution to victims.

Li, a former trading assistant at a unit of hedge fund founder Raj Rajaratnam’s Galleon Group, suffered catastrophic losses in January 2015 after moving nearly all of Canarsie’s portfolio into long, unhedged market index options whose value collapsed as prices went the other way.

Prosecutors also said Li overstated Canarsie’s performance to investors, and misled the U.S. Securities and Exchange Commission about some trades.

At the hearing, Resnik said Li made bad trades because he felt compelled to erase earlier losses, reflecting a “flawed” psyche from a life where Li had come to believe perfection was required.

Assistant U.S. Attorney Michael Ferrara said prison was justified to deter others, and show that is not acceptable to “lose 50-odd million dollars and lie to your investors.”

But he also said prosecutors spent much time wrestling with the case, noting Li’s “exceptional” cooperation and support even from a lawyer for some victims.

“He simply came in and said, ‘Here are my mistakes, here’s who I lied to,’” Ferrara said.

“My misconduct was, and is, my responsibility to bear alone,” Li told the court prior to being sentenced.

Resnik said after the hearing: “Owen looks forward to rebuilding his life and taking to heart the messages that the court gave him.”

The case is U.S. v. Li, U.S. District Court, Southern District of New York, No. 15-cr-00870.