Actually, Ernest is Jack Worthing, adopted at an early age by Mr Thomas Cardew who made him guardian of his granddaughter, Cecily, under the charge of the governess Miss Prism. Jack explains to be Jack in the country, but he has invented an alter ego, Ernest, who lives in the city, as a pretext to avoid his responsibilities. Even Algernon confesses he has invented a friend, Bunbury, who lives in the country and whose invalidity allows him to get away from London social obligations
Jack wants to marry Gwendolen but he has to overcome her mother, who doesn't accept he is a foundling. Algernon wants to marry Cecily and flirts with her in the guise of Jack's younger brother Ernest, but when Jack announces the death of his brother, creating a comic situation. Meanwhile Gwendolen goes to the country to find out more about Jack, whom she knows as Ernest, and discovers that Cecily is engaged to an Ernest Worthing, too.
Finally both men succed in marrying the women they want because Lady Bracknell allows her nephew Algernon to marry Cecily because she is the heiress of an immense fortune, and thanks to Miss Prism, the governor of the eldest son of her sister, Mrs Moncrieff, it turns out that Algernon and Jack are brothers and his real name is Ernest.