Dione Melville, 15, and two of her female friends were at a sleepover party when they took the ecstasy.
All three girls were taken to hospital when they fell ill after swallowing the tablets in East Calder.
The 16-year-old boy earlier pleaded guilty to supplying the drug to the schoolgirls at a house in Livingston between 19 and 26 March 2016.
The then 15-year-old dealer knew the drugs were "dodgy" because a girl he had sold them to the week before had also taken ill, Livingston Sheriff Court was told.
Katrine Craig, prosecuting, said that when he was filmed on CCTV selling the class A drug for Â£10 a pill, the youth had warned one of the girls to be careful and to "take the tablets in halves because they were lethal".
Dione's two friends survived but she died in the ambulance on the way to hospital.
The prosecution accepted his not guilty pleas to dealing the drug to boys aged 12, 16 and 17 and another 15-year-old girl.
Passing sentence, Sheriff Ferguson told the boy: "You have pled guilty to an extremely serious charge and this involved a class A drug ecstasy which is known to have at times disastrous effects, particularly when taken by young people.
"Initially what happened is that you passed this drug on to one young person and you became aware that that young person became ill.
"Despite that you continued to supply this drug to other youngsters aged just 15 years.
"You pled guilty to this charge and you are not responsible in law, it seems, for what happened thereafter, but you're responsible for selling a class A drug to other young people in your community and you have to meet the consequences of that.
"In my view there is no other realistic method of dealing with you other than a custodial sentence and you will go to detention for 18 months."
Dione's mother and father, Lesley and Michael, were at court for the sentencing.
Outside, Lesley said: "I think the sentence should have been longer but 18 months is a good start.
"He clearly thought he was going to get off with a community sentence and walk. I'm so happy."
A schoolboy who sold ecstasy tablets to a West Lothian girl who later died has been sentenced to 18 months detention.