In this Sunday, May 24, 2015 photo, hairstylist LaTanya Pinckney-Smith, right, hugs her friend, Candie Hailey, after working on her hair in New York in the Bronx neighborhood where they grew up. “I love her,” said Pinckney-Smith about her childhood friend of 20 years. “She has to look beautiful because I know how it is stereotyping African American women,” she added, concerned that Hailey’s upcoming appearance in housing court shouldn’t be a negative. Hailey is struggling to regain her welfare benefits, including city housing she lost following her incarceration at Rikers Island which ended after more than three years – with 2 1/3 in solitary confinement – when a jury trial found her not guilty. (AP Photo/Bebeto Matthews)

NEW YORK (AP) — A judge brokered a last-minute deal on Monday to dismiss criminal charges against a woman for jailhouse confrontations with guards during the three years she spent awaiting trial on Rikers Island, much of it in solitary confinement, before being acquitted by a jury and freed last spring.

After just half a day of testimony before Judge William Mogulescu in the Bronx, Candie Hailey, 32, agreed to plead guilty to four counts of disorderly conduct, a noncriminal violation, and prosecutors dismissed a felony and three misdemeanors related to her tumultuous time behind bars.

“I feel great,” said Hailey, whose time at Rikers and subsequent struggles to return to society were documented earlier this year by The Associated Press. “But I wouldn’t have ever had to agree to lesser charges of disorderly conduct if I hadn’t been there in the first place.”

Hailey, who was diagnosed with borderline character disorder, mood disorder and anti-social personality disorder while locked up, had faced up to seven years in prison for allegedly breaking a chair used to scan inmates’ body cavities for contraband. She was also facing misdemeanor charges of harassment, obstructing government administration and assault.

She was arrested in 2012 and charged with attempted murder after three women accused her of stabbing a baby during a fistfight. Hailey said she was the victim in the case and that the infant, who suffered a hairline skull fracture and needed three stitches, was injured when the stroller was knocked over by one of the women.

Her ensuing stay at Rikers was chaotic.

Of her first 29 months in jail, Hailey served about 27 of them in 23-hour isolation for breaking jailhouse rules and was frequently involved in confrontations and scuffles with guards. She regularly hurt herself by banging her head against her cell wall or cutting at her wrists with broken light fixtures. And at least eight times during her time in solitary, she was hospitalized for suicide attempts that included swallowing a hair remover product.

Criminal justice experts have said Hailey’s defiance was a common reaction to the continued use of solitary confinement for difficult inmates, especially those with mental health problems.

She was acquitted last year after a month long trial.

On Monday, a jail captain testified that she only heard, but did not see, Hailey break a piece off the security chair while her cell was being searched. Hailey’s lawyer, Patrick Higgins, questioned how his client could have damaged the device while her hands were covered with protective mitts designed to keep her from grasping anything.

Inmate advocates and Hailey’s supporters had asked the newly elected district attorney, Darcel Clark, to dismiss charges against Hailey, arguing she had been through enough.

Hailey had been offered a plea deal with time served before trial but rejected it, a spokeswoman for Clark said. Hailey said she refused to plead guilty to any of the criminal charges.