Judge Percy Anderson's surprise rejection came at the end of what was supposed to be Baca's sentencing. Under the agreement reached earlier this year with prosecutors, Baca faced a maximum of six months in prison and was eligible for probation.

Such a light sentence would "trivialize" the rule of law and would fail to address Baca's "gross abuse of the public's trust," Anderson said Monday.

"It's one thing to lie," Anderson said. "It's another thing entirely ... when the chief law enforcement officer of the county of Los Angeles is involved in a wide-ranging conspiracy to cover up abuse and corruption."

In his plea agreement, the 74-year-old Baca acknowledged ordering deputies to intimidate an FBI agent investigating his department and "do everything but put handcuffs on her." The investigation uncovered inmate beatings and found that deputies tried to stifle the probe by hiding an inmate who was an FBI informant.

Anderson said Baca's lies not only derailed the investigation, but "deputies were taught how to cover up abuses committed by fellow deputies, how to look the other way, how to shield the department from embarrassment — all of which led to fostering an us-versus-them mentality and unwritten codes that taught deputies that when an inmate dared attempt to harm a deputy, deputies would respond with enough violence to send that inmate to the hospital."

Before Anderson rejected the plea deal, Baca apologized in open court, saying he failed to be a leader.

"I stand here today humbled and filled with remorse for my mistakes as the sheriff of Los Angeles County," Baca told the judge, adding that the department and the public had trusted him. "I valued and honored that trust beyond measure. I took that task seriously ... It is my entire life's work."

Baca left court immediately after the hearing without speaking to reporters.

"We were blindsided," Baca's attorney, Mike Zweiback, said after the hearing. "To have this come out of the blue, for something that started as a very normal type of proceeding, is frustrating and it causes a lot of confusion."

Baca and his attorney must now decide whether to pursue another plea agreement or head to trial.

Zweiback told reporters that he can't accept more than a six-month sentence for Baca, given his client's diagnosis with early stage Alzheimer's disease, a revelation that became public last month.

"Then it's trial," Zweiback said, adding that Baca has explanations for his actions that haven't come out. "We're going to have to fight."

Zweiback said any time behind bars would exacerbate Baca's Alzheimer's and that his client would be particularly vulnerable among prisoners because of his former status as sheriff.

Zweiback cited a letter written by Baca's wife that said he frequently loses keys and ATM cards, forgets appointments, struggles with short-term memory and gets frustrated when he forgets the names of friends.

A hearing in the case was set for Aug. 1.

Baca led the nation's largest sheriff's department for 15 years. Popular and media-savvy, Baca used his platform as sheriff to travel the world touting progressive policing policies. He consistently dodged questions about any connection to the corruption, even as other former underlings pleaded guilty or were convicted.

Baca suddenly announced his retirement during his fourth term in office in 2014 as his department came under increasing scrutiny. Since then, 21 members of the sheriff's department have been convicted of federal crimes that involve beating inmates and obstructing justice.

Prosecutors argued that Baca's Alzheimer's didn't have any effect on his decision to lie to the government.

"His lies did not occur in a vacuum. He lied about his role, his involvement, his knowledge ... and he did so in order to either hide his involvement in that conspiracy or to save face," prosecutor Brandon Fox said. "That is not what a leader does. That is what a coward does."

Copyright 2016 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.