In November 1918, as World War I draws to a close, the German army withdraws from Marville, a small town in France that they have held for most of the conflict. A courageous member of the French resistance discovers that a bomb has been planted by the Germans and will detonate at midnight. He quickly informs a nearby British regiment and warns the townspeople, prompting them to flee the area for their safety.
To resolve this dilemma, Colonel MacBibenbrook (played by Adolfo Celi) selects the gentle, poetry-loving Scotsman, Private Charles Plumpick, to infiltrate Marville and deactivate the explosive device. Upon his arrival, Charles finds himself pursued by the remaining German soldiers and seeks refuge in a local insane asylum. The inmates, believing Charles to be the “Le Roi de Coeur” (King of Hearts), embrace him with warmth and joy.
Amidst the chaos, Charles inadvertently knocks himself unconscious, leading the inmates to seize the opportunity to escape the asylum and explore the now-deserted town. They return to their former professions: one becomes a barber (Michel Serrault), another a general (Pierre Brasseur), while others take on roles like a bishop and a brothel madam (Micheline Presle). Policemen and soccer players intermingle, enjoying a sense of freedom.
Upon regaining consciousness, Charles is initially confused and fails to recognize that the eccentric townspeople he encounters are actually former asylum inmates. He attempts in vain to rally them in the search for the bomb, but they are more preoccupied with anointing him as their King of Hearts.
As the situation escalates, German soldiers return, but the inmates cleverly commandeer their tanks and chase the soldiers away. Although British Army Scotsmen arrive on the scene, they are bewildered by the surreal happenings and retreat to report back to their colonel.
Now embraced as the King of Hearts, Charles develops a strong affection for Coquelicot (played by Geneviève Bujold), a virgin from Madame Eglantine's brothel assigned to keep him company. He is particularly motivated to locate the bomb for her sake, yet, like the others, she chooses not to worry about the impending explosion.
Charles eventually discovers that the bomb is located within the town's clock tower. Just in the nick of time, he ascends the clock tower and successfully disarms the bomb at midnight. Grateful for their savior, the inmates decide to celebrate for three years. As excitement builds, Charles and Coquelicot prepare for a romantic encounter, but their moment is interrupted by the arrival of the British Army.
Unaware that the “citizens” welcoming them are actually the inmates, Colonel MacBibenbrook allows his men to join in the festivities, becoming smitten with Madame Eglantine in the process. The next morning, as the regiment prepares to depart, Coquelicot expresses her sorrow over Charles's imminent return to the battlefield. In a desperate bid to keep him in Marville, she and several other former inmates bind him, leading to a bittersweet moment as they sit on a balcony watching the soldiers.
The tranquility shatters when a German regiment unexpectedly enters the town, culminating in a fierce clash where both armies face devastating losses. Following the confrontation, the townspeople cautiously return to Marville, while the inmates, now fully aware of their return to the asylum, begin their journey back.
Charles, having been honored for his bravery and the defusal of the bomb, grapples with the weight of returning to combat. He longs for the whimsical camaraderie he experienced with the inmates. In a poignant conclusion, he sheds his military uniform and walks naked through the town back to the asylum, choosing to join his quirky companions as one of them.