In the kingdom of Illyria, a nobleman named Orsino lies around listening to music, pining away for the love of Lady Olivia. He cannot have her because she is in mourning for her dead brother and refuses to entertain any proposals of marriage. Meanwhile, off the coast, a storm has caused a terrible shipwreck. A young, aristocratic-born woman named Viola is swept onto the Illyrian shore. Finding herself alone in a strange land, she assumes that her twin brother, Sebastian, has been drowned in the wreck, and tries to figure out what sort of work she can do. A friendly sea captain tells her about Orsino’s courtship of Olivia, and Viola says that she wishes she could go to work in Olivia’s home. But since Lady Olivia refuses to talk with any strangers, Viola decides that she cannot look for work with her. Instead, she decides to disguise herself as a man, taking on the name of Cesario, and goes to work in the household of Duke Orsino.
Viola (disguised as Cesario) quickly becomes a favorite of Orsino, who makes Cesario his page. Viola finds herself falling in love with Orsino—a difficult love to pursue, as Orsino believes her to be a man. But when Orsino sends Cesario to deliver Orsino’s love messages to the disdainful Olivia, Olivia herself falls for the beautiful young Cesario, believing her to be a man. The love triangle is complete: Viola loves Orsino, Orsino loves Olivia, and Olivia loves Cesario—and everyone is miserable.
Meanwhile, we meet the other members of Olivia’s household: her rowdy drunkard of an uncle, Sir Toby; his foolish friend, Sir Andrew Aguecheek, who is trying in his hopeless way to court Olivia; Olivia’s witty and pretty waiting-gentlewoman, Maria; Feste, the clever clown of the house; and Malvolio, the dour, prudish steward of Olivia’s household. When Sir Toby and the others take offense at Malvolio’s constant efforts to spoil their fun, Maria engineers a practical joke to make Malvolio think that Olivia is in love with him. She forges a letter, supposedly from Olivia, addressed to her beloved (whose name is signified by the letters M.O.A.I.), telling him that if he wants to earn her favor, he should dress in yellow stockings and crossed garters, act haughtily, smile constantly, and refuse to explain himself to anyone. Malvolio finds the letter, assumes that it is addressed to him, and, filled with dreams of marrying Olivia and becoming noble himself, happily follows its commands. He behaves so strangely that Olivia comes to think that he is mad.
Meanwhile, Sebastian, who is still alive after all but believes his sister Viola to be dead, arrives in Illyria along with his friend and protector, Antonio. Antonio has cared for Sebastian since the shipwreck and is passionately (and perhaps sexually) attached to the young man—so much so that he follows him to Orsino’s domain, in spite of the fact that he and Orsino are old enemies.
Sir Andrew, observing Olivia’s attraction to Cesario (still Viola in disguise), challenges Cesario to a duel. Sir Toby, who sees the prospective duel as entertaining fun, eggs Sir Andrew on. However, when Sebastian—who looks just like the disguised Viola—appears on the scene, Sir Andrew and Sir Toby end up coming to blows with Sebastian, thinking that he is Cesario. Olivia enters amid the confusion. Encountering Sebastian and thinking that he is Cesario, she asks him to marry her. He is baffled, since he has never seen her before. He sees, however, that she is wealthy and beautiful, and he is therefore more than willing to go along with her. Meanwhile, Antonio has been arrested by Orsino’s officers and now begs Cesario for help, mistaking him for Sebastian. Viola denies knowing Antonio, and Antonio is dragged off, crying out that Sebastian has betrayed him. Suddenly, Viola has newfound hope that her brother may be alive.
Malvolio’s supposed madness has allowed the gleeful Maria, Toby, and the rest to lock Malvolio into a small, dark room for his treatment, and they torment him at will. Feste dresses up as "Sir Topas," a priest, and pretends to examine Malvolio, declaring him definitely insane in spite of his protests. However, Sir Toby begins to think better of the joke, and they allow Malvolio to send a letter to Olivia, in which he asks to be released.
Eventually, Viola (still disguised as Cesario) and Orsino make their way to Olivia’s house, where Olivia welcomes Cesario as her new husband, thinking him to be Sebastian, whom she has just married. Orsino is furious, but then Sebastian himself appears on the scene, and all is revealed. The siblings are joyfully reunited, and Orsino realizes that he loves Viola, now that he knows she is a woman, and asks her to marry him. We discover that Sir Toby and Maria have also been married privately. Finally, someone remembers Malvolio and lets him out of the dark room. The trick is revealed in full, and the embittered Malvolio storms off, leaving the happy couples to their celebration.