Some time before the opening of Act 1, Ralph has fallen in love with Josephine, the daughter of Captain Corcoran, commander of HMS Pinafore. Buttercup, a peddler woman, has fallen in love with the Captain. Social class and pride keep both the Captain and his daughter from returning this affection, although both would like to do so. The Captain has pledged his daughter in marriage to Sir Joseph Porter, the First Lord of the Admiralty, who is in a social class even higher than the Corcorans'.
At the opening of Act 1, the sailors are busy preparing the ship for Sir Joseph's visit. Ralph and Josephine each sing a sad song bemoaning the fact that they both love in vain. Buttercup hints that she is hiding a secret, and Dick Deadeye grumbles that there is only trouble in store.
Sir Joseph arrive, attended by his sisters, cousins and aunts. He explains how he became Lord of the Admiralty and examines the crew, assuring them they are any man's equal, excepting his own!
Josephine finds Sir Joseph unbearable. Ralph confesses his love to Josephine. When she rejects him, he threatens suicide. She then confesses her love for him and they agree to elope. The act ends with great rejoicing.
Act II finds the Captain in despair that his daughter is not happy with Sir Joseph. Buttercup tries to cheer him, saying there is a change in store. Sir Joseph appears and says he wishes to call off the marriage since Josephine does not take kindly to him. The Captain suggests that his daughter may feel inferior to Sir Joseph and urges him to tell Josephine that difference in social rank should not be a barrier to marriage. Sir Joseph does this, not knowing that he is really convincing Josephine that it is acceptable for her to marry Ralph! Sir Joseph thinks she as accepted him and they are all happy again.
Dick Deadeye informs the Captain of the planned elopement and the Captain angrily halts the couple's get-away. Sir Joseph hears the disturbance, learns what has happened, sends the Captain to his cabin in disgrace and orders Ralph put in irons.
Buttercup must now come out with her secret: She tells that many years ago she was a nurse and had in her charge two babies - one a commoner and one of noble birth. Her secret is that she made the dreadful error of exchanging the babies, so that when they grew up, the nobleman became a sailor - Ralph - and the commoner became the Captain of HMS Pinafore. Sir Joseph orders the two men to assume their real identities, which prevents him from marrying Josephine (the daughter of a commoner), but permits her to marry Ralph and her father to marry Buttercup. Sir Joseph is left with Cousin Hebe. There is great rejoicing for a happy ending!