Ernest Worthing comes to London from his country home, intending to propose to Gwendolen Fairfax. Her cousin Algernon 'Algy' Moncrieff visits him and asks him why his cigarette case carries the inscription "From little Cecily with her fondest love to her dear Uncle Jack". Ernest reluctantly admits that his real name is Jack and that the case was a present from his ward Cecily Cardew, who lives in the country with her governess Miss Prism. He invented a troublesome brother named Ernest so that he would have the excuse to go up to London to see him whenever he wanted to, using the name himself while in town. Algy tells him he too has invented a sick friend, Bunbury, so that he can go to the country whenever he needs to.
Later, Jack meets Gwendolen and her mother Lady Bracknell at Algy's apartment. When the two are alone, Jack proposes to Gwendolen. She accepts, telling him that she could only marry a man named Ernest. Jack asks her if she might not be partial to another name, perhaps 'Jack', but she is adamant. Lady Bracknell returns and has a private interview with him. Although satisfied with his finances and world view, she is apalled to discover that he has no idea who his parents are. He is a foundling and was adopted by the Cardew family. He was given the Worthing surname as that was the current destination of Thomas Cardew, who found the baby in a handbag given to him in error at the Victoria train station cloakroom. Lady Bracknell refuses to give her consent until he identifies his real parents. Before leaving, Gwendolen promises to see him at his place in the country.
While Miss Prism takes a walk with the rector, Dr Chasuble, Algy visits Cecily, masquerading as Jack's brother Ernest. He is soon smitten with her. Jack arrives wearing mourning clothes and announces that Ernest has died while in Paris. But he is forced to accept Algy's impersonation to appease Cecily, who is now clearly taken with him. Jack tries to get Algy to leave but Cecily wants him to stay. She tells Algy/Ernest that she fell in love with him from the moment Jack first mentioned him, and has considered herself engaged to him for months. Algy asks Cecily to marry him and she accepts, telling him she could only ever really love a man named Ernest. Algy asks if any other name would do, but she is insistent.
Later, Jack and Algy both independently visit the rector, asking to be baptised. While Jack is out, Gwendolen arrives and meets Cecily in the garden. The two soon discover that they are both engaged to be married to Ernest Worthing. Jack and Algy soon appear and have to confess their deceptions. The two women call off the engagements and return inside the house while the two men argue over who is to blame and what to do next. Eventually the two couples are reconciled when Jack and Algy explain that they are both to be christened 'Ernest' that afternoon.
Lady Bracknell arrives and makes it clear that while she opposes Gwendolen's engagement, she supports Algy's as Cecily has a dowry worth £ 130,000. Jack insists that he won't give his consent to their union unless he is allowed to marry Gwendolen. What is more, according to the terms of the will, Cecily doesn't come of age until the age of thirty-five, another seventeen years! When Miss Prism arrives, Lady Bracknell recognises her as the nanny who twenty-eight years earlier took a baby boy for a ride in a pram; neither of them ever returned. Miss Prism admits that she lost the baby when she distractedly placed him in her handbag instead of the manuscript of a novel she was writing, and then left it at the Victoria cloakroom, only realising her mistake much later. Jack produces the bag in which he was found and Miss Prism recognises it as hers. Lady Bracknell explains that the baby was the son of her sister, meaning that Algy is his brother and Gwendolen his cousin. After a little searching, it is discovered that the baby's name was Ernest.