A villain, often known as a "black hat" or "bad man," is a stock character that may be based on either a historical tale or a work of literary fiction. The female variant of this character is referred to as a villainess. A character is defined as "a viciously spiteful person who is interested in or committed to immorality or crime; scoundrel; or a character in a drama, book, or the like, who represents a significant evil agent in the story," according to the Random House Unabridged Dictionary. A hero is the opposite of a villain in any story.
The function of the villain in a story is to provide a counterpoint to the hero character, and the storyline is advanced by the villain's nefarious goals or by the bad things they do.