A teenager has been jailed for 22 years for hatching a plot to behead a British soldier inspired by the murder of Fusilier Lee Rigby.

Brusthom Ziamani, 19, was arrested in an east London street carrying a 12in (30.5cm) knife and a hammer in a rucksack, having earlier researched the location of Army cadet bases in the south east of the capital.

Earlier, he had shown his ex-girlfriend weapons, described Fusilier Rigby's killer Michael Adebolajo as a "legend" and told her he would "kill soldiers".

The court heard he was a "lone wolf" who had been radicalised after being befriended by members of a radical Muslim organisation which held meetings and demonstrations in London.

He was found guilty of preparing an act of terrorism on or around August 20 last year following a trial at the Old Bailey.

Sentencing him, Judge Timothy Pontius said: "A realistic and sensible assessment of the whole of the evidence leads inescapably to the conclusion that this defendant, had he not by sheer good fortune been spotted and stopped by the police on the street in east London, would have carried out the intention he had so graphically expressed to his ex-girlfriend just a few hours before."

The judge told Ziamani that he would have to serve at least two-thirds of his 22-year sentence before being eligible for parole, adding that he would extend the time he would spend on licence after his release by five years.

Earlier, in mitigation, Ziamani's lawyer, Naeem Mian, said his client was not an "entrenched extremist" but a young man who while destitute had been groomed by people who were "more sophisticated and mature" than him.

He said: "It is worrying to say the least that those who groomed him are able to groom and radicalise a young man in such a short period of time.

"On any view it is a tragic case because this young man will spend a long time in custody after which he will inevitably be unemployable. His foolish, naive acts have resulted in him throwing his life away at his tender age.

"He has nothing to look forward to now. The only glimmer of hope he has is the fact his parents - in particular his mother - has been to see him a number of times since his conviction. They are still not comfortable with the fact he has converted to Islam. As you would expect of caring and loving parents, they have been to see him."

Ziamani stood impassively in the dock as the sentence was handed down.

His trial heard that he had "reverted" to Islam early last year and was kicked out of home in Camberwell, south London, by his parents.

He initially turned to his local mosque for support before he fell in with the Muslim group al-Muhajiroun - or ALM - who gave him money, clothes and a place to stay.

He attended their talks in the basement of a halal sweet shop in Whitechapel and bought a black flag to take on their demonstrations, saying "I'm going to rock it everywhere I go in the Kaffirs' face".

After just months learning about the Muslim religion, he posted comments on Facebook that he was "willing to die in the cause of Allah" and saying: "Sharia law on its way on our streets. We will implement it, it's part of our religion."

At the time he was first arrested last June on an unrelated matter, police found a ripped-up letter in his jeans pocket in which he wrote about mounting an attack on a British soldier and expressed the desire to die a martyr.

But Ziamani denied he was planning a copycat terror atrocity like the murder of Fusilier Rigby.

On the letter, he said: "I was ranting and raging about the situation in Muslim countries which was described in these talks. I did not believe it at all."

He explained his Facebook postings as an attempt to "fit in" with the ALM group, saying: "I did not believe it. I wanted to fit in with these people because they were giving me places to stay and they did not like moderate Islam."

He denied that he had a terror "tool kit" of a hammer, knife and flag at the time he was arrested last August, saying he needed weapons because he felt threatened after getting out of a credit card theft operation.

And he said the black flag was packed just in case he was called to a demonstration at the last minute by text.

He rejected the suggestion that he styled himself as Mujahid Karim after one of Fusilier Rigby's killers, saying the Muslim first name meaning "fighter, a warrior" suited his character because he used to do boxing and wrestling.

Ziamani was born in London to Congolese parents. His mother worked as a nursery nurse and his father was a psychiatric nurse.

He said he first became interested in Islam at the age of 15 through rap music and decided to convert again in the months before his arrests.

During that time, he went to the Camberwell Mosque, split up with his girlfriend and wore an Islamic robe but tucked it into his trousers when he went home to stop his Jehovah's Witness parents finding out.

After he was convicted, Commander Richard Walton, from the Counter Terrorism Command, said: "This case starkly illustrates one of the threats we currently face in the UK.

"Ziamani was an impressionable young man who became radicalised, then rapidly developed an extremist, violent mindset. Over a series of months he ultimately developed a desire to carry out a terrorist attack on British soldiers.

"The outstanding professional work of my officers in the SO15 Counter Terrorism Command, supported by MI5, has probably prevented a horrific terrorist attack taking place on the streets of London."