OAKLAND -- A 31-year-old Oakland man accused of being an accessory to a felony in connection with the fatal shooting of a 25-year-old last year at the Occupy Oakland encampment will be sent to prison for more than three decades.

In a plea deal reached with the Alameda County District Attorney's Office, Issac McDaniels avoided a possible life sentence in exchange for admitting that he participated in the murder and sexually assaulted a woman five days later.

In fact, it was the sexual assault that had McDaniels facing life in prison because he was charged with kidnapping the 22-year-old victim.

The plea deal came as attorneys were preparing for a jury trial in which McDaniels faced 32 years to life in prison for numerous felonies, including assault, accessory to a felony, forced oral copulation, second-degree robbery and kidnapping.

Instead, the district attorney's office agreed to drop the kidnapping charge in exchange for McDaniels admitting to all the other crimes, including a prior robbery conviction. In doing so, McDaniels was guaranteed to be released from prison in 35 years and eight months.

"The sentence of over 35 years will ensure that he is held responsible for his crimes," said deputy district attorney Tim Wellman.

McDaniels was originally arrested for his role in the shooting death of Kayode O. Foster, 25, near the BART entrance on Frank Ogawa Plaza. The shooting occurred Nov. 10, 2011, at the height of the Occupy Oakland encampment and led to more residents demanding that the illegal tent city be taken down.

McDaniels said he helped beat Foster and gave his gun to accused killer Norris Terrell, 20, before the fight with Foster began. That fight led to Terrell being accused of shooting and killing Foster.

Terrell was arrested and charged with murder, but McDaniels was never charged with murder because prosecutors did not have evidence proving that he knew Terrell was going to shoot Foster.

McDaniels faced only seven years in prison for his involvement with the Foster killing but soon learned that he faced a lifetime for sexually assaulting a woman five days later.

The sexual assault occurred about 1 a.m. on East 25th Street as the woman walked home from work. The woman testified during a preliminary hearing that McDaniels followed her and then forced her into a secluded area before making her perform oral sex at gunpoint.

DNA collected at the scene of the crime was linked to McDaniels. The woman also identified him as her attacker.

McDaniels almost was given a more lenient punishment after the district attorney's office offered him a deal last year in which he would have had to serve 16 years in prison. McDaniels agreed to the deal, but the victim would not agree, saying she believed McDaniels needed to spend more time in prison.

Wellman said the victim agreed with the latest plea deal that was offered.

McDaniels will be sentenced Jan. 24. His attorney, David Bryden, could not be reached for comment.