Andrew Ferguson made the threat to use a blade to massacre pupils at St Mungo’s High School in Falkirk, Stirlingshire, on Twitter.
The town’s sheriff court was told that Ferguson, 17, who has since left the Roman Catholic school, tweeted the alarming comments on 5 June.
He also tweeted that he hoped the family of the school’s deputy headmaster, James Murphy, “would die in a massacre” and posted derogatory racial remarks about the pastoral head of the school, Ann-Marie Jess, adding that he wanted to assault her.
Ferguson, of Camelon, Falkirk, who appeared in court dressed in a grey suit, white shirt and tie, pleaded guilty to using threatening and abusive behaviour.
He had been due to face trial yesterday.
Graham McLachlan, the depute fiscal, said Ferguson had no previous convictions.
Solicitor-advocate Martin Morrow, defending, said that his client had now left the 1,350-pupil school.
Sheriff William Gallacher deferred sentence on Ferguson for a social work report until 2 October.
He continued Ferguson’s bail, on condition that he does not enter the school “unless invited”, and that he makes no attempt to contact Mr Murphy or Ms Jess.
The sheriff said the case caused him “some concern” and background reports had to be carried out.
He said: “I haven’t heard any background yet, but it is obviously a very unpleasant and very serious matter.
“I want to know how someone with no past convictions could behave in this way.”
St Mungo’s High School, in Merchiston Avenue, Falkirk, is the only Roman Catholic high school in the Falkirk Council area. It moved to a new building on the site of the old school’s sports fields five years ago.