LONDON — An Al Qaeda-inspired extremist was sentenced to life without parole Wednesday for hacking to death an off-duty British soldier on a London street in front of horrified passers-by.

Images of Michael Adebolajo, 29, holding a butcher knife and cleaver with bloodied hands in the moments after the May 22 killing of Lee Rigby shocked people around the world and sparked fears of Islamist terrorism in Britain.

The self-described ‘‘soldier of Allah’’ was sentenced at Central Criminal Court along with his accomplice, Michael Adebowale, 22, who was sentenced to life with a minimum of 45 years in jail because of his age and lesser role in the murder.

The day ended in drama when both men were pinned to the ground and led out of the courtroom after scuffling with guards and shouting at the judge moments before their sentences were read out.

Adebolajo yelled ‘‘Allahu akbar’’ — God is great — while Adebowale called out ‘‘that’s a lie’’ as the judge told them they had been radicalized.

Outside the court, protesters from two far-right groups erected gallows and demanded death for the two men.

The pair were convicted in December of murdering Rigby, 25, who was walking near his barracks in south London when the men ran him over with a car. They then dragged his body onto the road, and repeatedly stabbed him with knives.

Adebowale attacked his torso, while Adebolajo attempted to cut off the soldier’s head with a cleaver.

Moments after the killing, Adebolajo was filmed delivering a rambling monologue justifying the attack.