A 17-year-old boy who was "hours away from committing an act of atrocity" in Cardiff has been detained indefinitely and must serve at least 11 years.
Lloyd Gunton was arrested after researching the security arrangements of a Justin Bieber concert, Birmingham Crown Court heard.
The jury was told he plotted to commit mass murder in an Islamic State-inspired vehicle attack.
Police investigated after he uploaded terror-related social media posts.
Gunton, from near Llantrisant, south Wales, was arrested after he uploaded social media content to photo-sharing social media site Instagram in late June 2017 which promoted jihad and supported al-Qaeda.
The former A-level student, who has an autism diagnosis, had published images of terrorists, as well as pictures of the so-called Islamic State flag, and photos encouraging a terrorist attack in Cardiff.
Police found the password for the account was "truck attack".
One post read: "May Allah bring terrorism to Cardiff on 30th June."
He had researched how to carry out a vehicle ramming attack and how to stab and kill and had also looked into the security arrangements of the Justin Bieber concert in Cardiff's Principality Stadium.
His internet history included searches for "Isis beheading video", "how to create a terror attack" and "what does getting shot feel like".
When arrested, the teenager was found with a gutting knife and a hammer in his school rucksack, and the "martyrdom letter" said he was a "soldier of the Islamic state" and "more attacks will follow".
He was found guilty of one charge of engaging in the preparation of a terrorist act, two charges of encouraging terrorism, and a further two charges of possessing terrorist information.
He was detained at Her Majesty's Pleasure at Birmingham Crown Court and will be returned to a young offenders institution where he has been held since his conviction.
An order banning his identification was lifted by the court.
Judge Mark Wall QC told Gunton: "At the time of your arrest you were within hours of committing an act of atrocity on the streets of Cardiff.
"It is not possible to estimate how many people would have been murdered or seriously injured by your actions as the attack was foiled before you could undertake it.
"I am sure that you planned not just the killing of one person but rather mass murder."
The judge said Gunton's diagnosis of autism made him "something of a loner and someone more easily impressed by the things you read on the internet".
"Yours is not a condition from which you will recover," said Judge Wall.
"It is important that, having been tempted to commit a serious offence such as this, you are under some form of supervision for the rest of your life."