Viola is shipwrecked on the coast of Illyria and she comes ashore with the help of a captain. She loses contact with her twin brother, Sebastian, whom she believes to be dead. Disguising as a young man under the name Cesario, she enters the service of Duke Orsino through the help of the sea captain who rescues her. Orsino has convinced himself that he is in love with Olivia, whose father and brother have recently died, and who does not wish to see any suitor till seven years, the Duke included. Orsino uses Cesario as an intermediary to profess his passionate love before Olivia. Olivia, believing Viola to be a man, falls in love with this handsome and eloquent messenger, while Viola has fallen in love with the Duke who regards her as his confidant.
In the comic subplot several characters conspire to make Olivia's pompous steward, Malvolio, believe that his lady Olivia has fallen for him. It involves Olivia's uncle, Sir Toby Belch; another would-be suitor, a silly squire named Sir Andrew Aguecheek; her servants Maria and Fabian; and her fool, Feste. Sir Toby and Sir Andrew engage themselves in drinking and revelry, thus disturbing the peace of their lady's house till late into the night prompting Malvolio to chastise them. This provokes Sir Toby, Sir Andrew and Maria to plan revenge on Malvolio. They convince Malvolio that Olivia is secretly in love with him through a love letter written by Maria in Olivia's hand asking Malvolio to wear yellow stockings cross-gartered, to be rude to the rest of the servants, and to smile constantly in the presence of Olivia. Malvolio finds the letter and reacts in surprised delight. He starts acting out the contents of the letter to show Olivia his positive response. Olivia is shocked by the changes in Malvolio who has seemingly lost his mind. She leaves him to the contrivances of his tormentors. Pretending that Malvolio is insane,they lock him up in a dark chamber. Feste visits him to mock his "insanity", once disguised as a priest, and again as himself. At the end of the play Malvolio learns of their conspiracy and storms off promising revenge, but the Duke sends Fabian to pacify him.
Meanwhile Sebastian (who had been rescued by a sea captain, Antonio) arrives on the scene, which adds to the confusion of mistaken identity. Mistaking him for Viola, Olivia asks him to marry her, and they are secretly united in a church. Finally, when Viola and Sebastian appear in the presence of both Olivia and the Duke, there is more wonder at their similarity. At this point Viola reveals she is really a female and that Sebastian is her lost twin brother. The play ends in a declaration of marriage between the Duke and Viola, and it is learned that Toby has married Maria.