In Shakespeare's Hamlet, the ghost that Hamlet and the others see is very real to them. Shakespeare was a relatively savvy dramatist: he knew what his audiences wanted to see. He would include elements that the people could identify with. For example, in Macbeth, Macbeth is a tyrant. The shock they would have experienced when Macbeth killed Duncan would be replaced by inner-conflict, for it would have raised a question of common debate: was it ever justified to kill a king, which is what Macduff does at the end of the play when he defeats Macbeth in battle.
Another aspect of Shakespeare's plays that would have appealed to his Elizabethan audience was the presence of the supernatural. This did not only include ghosts (which we see in several of his plays), but also fairies, sprites, witches, etc. Elizabethans were completely certain the appearance of Hamlet's dead father was possible. They shared...
...the definite belief in apparitions or ghosts...they truly believe[d] in the existence of these spirits [and had] a list as to the characteristics of ghosts.
Hamlet's concerns reflect the fears of the audience: is the ghost evil or really Hamlet's father? The fear is not of seeing a spirit, but whether the spirit is Hamlet's father in need of his son's help, or an evil spirit trying to lure Hamlet to his soul's destruction: for in killing Claudius (a king), Hamlet would forfeit his immortal soul—killing a king was considered a mortal sin.
Hamlet reports to the others that the Ghost is an honest spirit (though he will search for further proof of Claudius' guilt throughout the play). He makes the others present in Act One, scene five, promise to keep what they have seen secret. They agree immediately. However, as he urges their continued silence, the Ghost speaks to them as well:
Never to speak of this that you have seen.
Swear by my sword.
The Ghost demands this three times. All agree.
Had the Ghost not appeared, but strange occurrences taken place, the audience would have taken these as signs as messages from of the supernatural (omens). That the Ghost appears is something they believe without a doubt. As the players in scene five agree to keep the secret of what they have seen, they show that they believe in ghosts—reflecting the beliefs of the audience.
The Ghost is real, we can assume, in that all the men see the same thing at different times: first the guards, then also Horatio, and finally even Hamlet. Based upon the beliefs of the audience, reflected in Hamlet's beliefs, we can assume that Shakespeare presents the ghosts as real, not a part of the men's imaginations.