Dominic Palmer stabbed the 15-year-old multiple times at 1am on September 30 last year, West Midlands Police said.
The boy had been dropped off outside the Hussaina Mosque in Small Heath, Birmingham, by his father and was attacked minutes later.
Palmer, 29, fled the scene as the teenager's father and members of the congregation ran to help him.
The boy was taken to Birmingham Children's Hospital where he was treated for injuries to the head and neck before being put in an induced coma.
CCTV at the defendant's block of flats showed him returning with bloodstained hands before he went to attack a second victim.
He stabbed a 59-year-old woman in the face a few hours later as she was walking to work in Cyril Road.
She suffered knife wounds to her nose, jaw and head and officers said she may not have survived if a member of the public had not come to her aid.
Unemployed Palmer denied two counts of attempted murder but was convicted by a jury and handed a 20-year minimum prison term on Friday.
Detective Inspector Richard Marsh, who led the inquiry, said: "These were savage attacks; without intervention of members of the public and medical assistance both incidents could have resulted in fatal consequences.
"Palmer has never offered any explanation for his actions. The awful attack on the 15-year-old boy happened outside a mosque and there were suspicions initially it was racially motivated, but that was later discounted and it appears his victims were simply in the wrong place at the wrong time.
"And although Palmer has a history of mental illness the judge concluded that did not play a part in these attacks.
"We quickly arrested Palmer and seized CCTV showing his movements immediately before and after both stabbings - his bloodstained jacket was found discarded on a grass bank near his flat and bloodstained clothing and a knife were recovered from within his premises.
"His victims are still dealing with the physical and psychological effects of these attacks and I wish them well with their ongoing recoveries.
"I'd also like to thank them for the courage and resilience they've demonstrated throughout the investigation and subsequent court trial, and I hope the fact Palmer has been taken out of society for a long time will offer them some comfort."