LOS ANGELES — Former rap mogul Marion “Suge” Knight pleaded no contest Thursday to voluntary manslaughter after he ran over two men, killing one, nearly four years ago.

The Death Row Records co-founder entered the plea in Los Angeles Superior Court and has agreed to serve 28 years in prison.

Knight was charged with murder, attempted murder and hit-and-run after fleeing the scene of an altercation in January 2015 outside a Compton burger stand. Knight and Cle “Bone” Sloan, a consultant on the N.W.A. biopic “Straight Outta Compton,” were involved in a fistfight that ended with Knight clipping the man with his pickup truck and running over businessman Terry Carter, who died from his injuries.

Knight’s attorneys have said he was acting in self-defense and was fleeing armed attackers when he ran over Carter and Sloan.

During Thursday’s hearing, Knight answered Judge Ronald Coen’s questions, loudly and quickly saying “no contest” when the judge asked for his plea.

The plea deal calls for Knight to serve 22 years in prison on the voluntary manslaughter count, and another six years because it is a third strike violation.

Knight, 53, was a key player in the gangster rap scene that flourished in the 1990s, and his label once listed Dr. Dre, Tupac Shakur and Snoop Dogg among its artists. Knight lost control of the company after it was forced into bankruptcy. He has prior felony convictions for armed robbery and assault with a gun. He pleaded no contest in 1995 and was sentenced to five years’ probation for assaulting two rap entertainers at a Hollywood recording studio in 1992.

He was sentenced in February 1997 to prison for violating terms of that probation by taking part in a fight at a Las Vegas hotel hours before Shakur was fatally wounded in a drive-by attack as he rode in Knight’s car just east of the Las Vegas Strip. Shakur’s slaying remains unsolved.

He had faced life in prison if convicted of murder for killing Carter.