During World War II, newly commissioned Ensign Willis Seward "Willie" Keith Robert Francis reports to the minesweeper USS Caine, where he meets career officer Lieutenant Stephen Maryk, Van Johnson the ship’s executive officer, and aspiring novelist and communications officer Lieutenant Thomas Keefer, José Ferrer. Soon after, Lieutenant Commander Philip Francis Queeg, Humphrey Bogart, is assigned command of the Caine. The eccentric Queeg instills strict discipline on a lax crew, making him unpopular with them, but admired by Keith.
During a gunnery target towing exercise, Queeg is distracted berating Keith and Keefer over a crewman’s appearance, resulting in the ship steering over and cutting the towline, setting the target adrift. Queeg tries to cover up the incident.
Assigned to escort a group of landing craft during an invasion of a small Pacific island, Queeg abandons his mission before he reaches the designated departure point, and instead orders the dropping of a yellow dye marker, leaving the landing craft to fend for themselves. Queeg asks his officers for their support, but they remain silent and nickname him "Old Yellowstain", which implies cowardice.
Keefer, believing Queeg to be paranoid, encourages Maryk to consider relieving Queeg on the basis of mental incapacity under Article 184 of Navy Regulations. Though Maryk angrily rejects that possibility, he does begin keeping a medical log documenting the captain's behavior.
When strawberries go missing from the officers' mess, Queeg convenes an elaborate investigation to determine the culprit. The investigation involves searching the ship and stripping all crew members. Convinced of Queeg's instability, Maryk asks Keefer and Keith to go with him to see Admiral Halsey about the matter. Arriving aboard Halsey's flagship, Keefer backs down and they return to the ship.
At the height of a typhoon, Maryk urges the captain to reverse course into the wind and take on ballast, but Queeg refuses and virtually freezes up on the bridge. Maryk, supported by Keith, relieves Queeg of command under Article 184. The Caine returns to San Francisco, where Maryk and Keith face a court-martial for mutiny. Lieutenant Barney Greenwald, Lee Marvin, a temporarily grounded naval aviator and an attorney before entering the Navy, becomes Maryk's defense counsel.
At the court-martial, Keefer claims he never observed any mental illness in Queeg and was "flabbergasted" when he was relieved. Under Greenwald's relentless cross-examination, Queeg exhibits odd behavior on the stand, including his habit of rolling two steel balls in his hand symbolizing his mental instability, and Maryk is acquitted.
Following the acquittal, the officers of the Caine hold a party, where Keefer receives a frosty reception from Maryk. A drunken Greenwald arrives and berates all the officers for not appreciating Queeg's long service and failing to give him the support he asked for, instead of deriding him as an incompetent. Greenwald claims their mistreatment of Queeg, who had been suffering from "battle fatigue" from his previous combat service in the Atlantic, caused the captain to ultimately become indecisive during the typhoon. He denounces Keefer as the real "author" of the mutiny and throws a glass of champagne, the "yellow wine", in Keefer's face. The rest of the officers walk out, leaving Keefer alone in the room.
Keith, now married to his girlfriend May Wynn, is promoted to Lieutenant (junior grade), and assigned to a new Sumner-class destroyer commanded by now-Commander De Vriess, his first captain on the Caine.