A fictional work depicts imaginary events - but if a real person can be identified in your work of fiction, this person may be able to bring a libel suit against you. As in any defamation suit, a public person needs to show actual malice and a private person may only need to show negligence in order to bring a successful suit. Writer's usually must guarantee to a publisher, often in a written contract, that they have not libeled anyone in their work, so it is often wise to have an attorney review your work before submitting it for publication.
There are several ways your depictions of characters can cause you legal headaches - one is where you, as the author, attack an actual person and this person can be identified by the readers. Another way is when you "disguise" the real person by altering some aspects of this person (with a false name or false description, perhaps) but the real person can still be identified. Another is when you, as author, pattern a character after someone you once knew but claim to have totally forgotten. Another is when you describe a real person but do not even know this person - the description is truly accidental.
Disclaimers, often seen in novels, that state that all characters are imaginary, that all events are imaginary, and that any resemblance to people living or dead is totally coincidental, do not protect an author if readers can recognize real events or people.
Written consent forms can protect an author if persons discussed in the author's work are willing to sign them, agreeing not to sue for libel. The author can also purchase insurance coverage - several publishing companies now include writers in their policies as a normal course of doing business with them. This insurance does not reduce the risk of being sued, but does reduce the financial impact on the author and/or publisher.