Bosses at education authority Birmingham City Council have taken High Court action following weeks of protests outside Anderton Park Primary School.
They asked a judge to impose an injunction at a High Court hearing in London on Friday - while children were on half-term holidays.
Mrs Justice Moulder made an order barring protesters from gathering outside or near the school, from distributing leaflets and from making offensive comments about staff on social media.
The council has published her order on its website.
She made the order against three named people and "persons" unknown.
But she said protesters had been given no warning of the council's application.
She said a judge should reconsider the injunction at a hearing in Birmingham on June 10.
Any protester could also apply to discharge the order, she said.
Council leader Ian Ward said, after Friday's hearing, that legal action had been taken pending children's return to school on Monday and he called on parents to "engage in constructive dialogue" if they had concerns.
"All our schools must be safe spaces and we will not tolerate the ongoing intimidation of parents, hard-working school staff and local residents," he said.
"This interim injunction has been secured in time for the return to school on Monday and now hopefully the pupils will be able to continue their education in peace for the remainder of the summer term."
He added: "We'll continue to support the school and its staff and I would urge parents to take this opportunity to engage in constructive dialogue with the school about any concerns they may have."
A council spokesman said bosses had decided to make an "urgent" High Court application "in the light of increasing fears for the safety and well-being of the staff".
He said there had been a "serious escalation" in protests in the week before half-term and bosses had concluded that the "risk of harm" had become "too serious to tolerate".
Education Secretary Damian Hinds, who has previously called the demonstrations "unacceptable", welcomed the injunction.
Stay up to date with the latest news stories from a Christian perspective. Sign up to our daily newsletter and receive more stories like this straight to your inbox every morning.