Prince Karl Franz is heir to the (fictitious) German kingdom of Karlsberg. He has grown up fatherless, under rather gloomy military conditions of castle life ("By our bearing so sedate"). He has been educated by tutors, including the kindly Doctor Engel, who has taught him the songs of his alma mater, the venerable University of Heidelberg ("Golden Days"). Karl Franz has been promised in marriage, since childhood, to the Princess Margaret, but he has never met her. His grandfather, King Ferdinand, sends him to the University incognito, to live as an ordinary student, and improve his social skills. Karl Franz sets off under the watchful eye of Doctor Engel, accompanied by his snooty valet Lutz, who has his own assistant, Hubert.
At Heidelberg, Herr Ruder keeps the rustic Inn of Three Gold Apples ("Garlands Bright"). His beautiful niece Kathie waits tables in the inn's beer-garden. The inn is very popular with the students, who come there to drink and sing ("Drink! Drink! Drink!" and "To the Inn We're Marching"). Karl Franz, the finicky Lutz, and Hubert arrive for the spring term and take rooms at the Three Gold Apples, to the delight of Engel and the disgust of Lutz ("In Heidelberg Fair," "Welcome to Prince"). He falls in love, almost at first sight, with Kathie, who returns his affection ("Deep in My Heart, Dear"). But he is a royal heir, and she is a commoner.
Karl Franz also makes friends with three students: Detlef, Lucas and von Asterberg. They share the camaraderie of student life, with nights of enthusiastic drinking and singing ("Overhead the Moon is Beaming"). Karl joins their student corps ("Come Sir, Will You Join Our Noble Saxon Corps?").
As the term passes, Karl Franz and his friends continue to enjoy student life ("Farmer Jacob Lay-a-Snoring", "Students' Life"). By the end of the term, Karl Franz and Kathie are deeply in love.
But then Karl Franz receives a surprise visit from Princess Margaret and her mother. They bring news that the king is ill and commands the prince to return home for the ceremony of betrothal to the princess. After they leave, Karl Franz and Kathie consider eloping to Paris. But Doctor Engel and Count Von Mark (the prime minister of Karlsberg) remind the prince of his duty to his kingdom. Karl Franz reluctantly agrees to obey the king's command. He promises Kathie that he will return soon ("Farewell, Dear"). He takes leave of his friends ("Thoughts Will Come Back to Me"), and the students salute the University ("Gaudeamus Igitur").
Back in Karlsberg, two years pass, with Karl Franz unable to return to Heidelberg. His grandfather has died, and Karl Franz is now King. His life is bound up in court ceremony ("Waltz Ensemble"). Princess Margaret has also had a secret relationship with another man, Captain Tarnitz ("Just We Two"). But as King, Karl Franz must honor the betrothal to Margaret ("Gavotte"). Margaret knows that Karl Franz has long pined for an old love, and she has heard rumors that in Heidelberg, he fell in love with a tavern keeper's niece.
Word arrives from Heidelberg that Doctor Engel has died there. Karl Franz is persuaded to visit Heidelberg for a brief reunion with his old friends, and he hopes to see Kathie again ("What Memories").
Princess Margaret goes to Heidelberg first, and secretly visits Kathie. Margaret persuades her that for the good of the kingdom, she must break off with Karl Franz. They agree that Kathie will tell Karl Franz she is in love with another man and is going to marry him. Karl Franz will then finally be free to accept Margaret, who has come to love him. Meanwhile, the students of Heidelberg continue their merry ways ("Sing a Little Song", "To the Inn We're Marching (reprise)," "Overhead the Moon is Beaming (reprise),","Come Boys, Let's All Be Gay Boys").
Karl Franz arrives, meets his old friends and visits Kathie. True to her promise, she tells him of her fictitious new love and plans to marry. Karl Franz resolves to marry Margaret without further delay, but Kathie will always be his true love (Reprise of "Deep in My Heart, Dear").