A school went into “lockdown” when travellers with up to 30 caravans moved onto its playing field while pupils were in their lessons.
They parked up at Hazelwick School in Crawley, West Sussex, after a padlock securing the grounds was cut open.
GCSE exams had to be moved, pupils were kept in their classrooms during breaks, and they had to travel in groups to go to the toilet.
Sussex Police arrived at 11:00 BST and served a notice to leave.
The travellers initially pulled up on a verge close to the 1,800-pupil school, but quickly moved on to the playing field.
They set up pens for their horses and more travellers arrived.
The school confirmed it went into “lockdown” over concerns for pupils’ safety, and students sitting PE and Latin GCSE exams had to be moved into another hall.
Head teacher Ann Fearon said: “I am angered and frustrated by this.
“There is no getting away from the fact it’s been an extremely difficult day, and having that number of people illegally on your grounds is very annoying and worrying.”
At 15:00 police formally gave the group an hour to leave, but anticipated it would take longer to move them on.
A West Sussex County Council spokesman confirmed 22 caravans initially parked up on the site “having forced entry on to the school field by cutting a padlock”.
The travellers were making their way out by 18:30.
One traveller, who did not wish to be named, said they did not know the land was school property – and are now heading to Scotland.
They are believed to be the same group who set up camp in the town’s Manor Royal area and left after being given notice to quit by the landowner, police and the local authority.