Inverness Sheriff Court was told that 19-year-old Adam Nicolson, of Torvean Avenue, befriended the girl – described as “vulnerable” by fiscal depute Fiona Murray – in May last year.
But the following month, on June 12, he met her at lunchtime and gave her ecstasy tablets and powder.
Mrs Murray said: “She took four lines before returning to school. The following day, she took more ecstasy and as staff suspected she had taken drugs, she was taken to hospital.
“But when she was released the same day, she went to his house and he gave her more ecstasy.”
Defence solicitor Duncan Henderson said his client, who admitted supplying the drug to the girl, “did not benefit from this as he gave her the drugs because they were friends.
“He has no on-going drug problem.”
Sentencing Nicolson, Sheriff Chris Dickson said: “This is a serious matter which could have had serious consequences.”