The horrific discovery was made at a school in Edinburgh, just as classes were about to get under way yesterday morning.
It is understood the body was found by a parent who thought they saw a doll hanging from a tree.
Staff immediately called parents to ask them to collect their children and the school was shut for the rest of the day.
A source close to the investigation said the death was being treated as suicide.
Edinburgh Council said it was offering support to staff and more than 250 pupils at St John Vianney RC Primary, although it was not thought any children saw the body.
Police were called after the body was found in a wooded area within the grounds of the school.
The man is believed to be in his late 20s or early 30s and police are still trying to establish his identity.
A woman, whose grandson attends the school in the Inch area of the city, said: "I live near the school and when I first saw all the police I panicked, thinking it could be a shooting.
"My daughter called me to say I had to collect my grandson."
Although the school was closed immediately, some parents were still arriving as late as 1pm to collect their children.
The school is surrounded by a high fence and it is not known if the man walked into the grounds yesterday morning or climbed over the fence while the school was closed.
A police spokesman said: "At this stage the circumstances leading to the death of the male are being investigated and a report will be sent to the procurator-fiscal."
Edinburgh Council said no children saw the body, but they were sent home as a "mark of respect".
The school is expected to reopen today.