A period costume romance is joined to an intelligent history lesson in “A Royal Affair,” one of the few films that succeeds in depicting what the Enlightenment was all about—and how its message of rationalism could easily succumb to the human passions that the movement so strenuously opposed.

Nikolaj Arcel’s film is essentially the story of Johann Friedrich Struensee (1737-1772), a German doctor who became court physician to Denmark’s mentally unstable King Christian VII and gradually took over the reins of government, becoming the functional ruler for little over a year from December 1770 to January, 1772. A child of the Enlightenment, he was devoted to the thought of Helvetius and Voltaire and wrote anonymously in a vein similar to theirs; and now in a position to do so, he undertook a remarkable series of reforms that put Denmark, until then an extremely traditionalist realm, at the forefront of progressivism in Europe. Unfortunately, his mistakes—most notably an affair with Christian’s English wife Caroline Matilda, which resulted in the birth of a daughter claimed as the king’s—brought him down in a coup headed by the Dowager Queen Juliana Maria, and he was executed shortly afterward.

Arcel and his co-screenwriter Rasmus Heisterberg construct Struensee’s story as a long flashback occasioned by a letter penned to her children by the exiled Caroline Matilda as she lay dying. This results in a film that joins a tale of political machination to a romantic tragedy. The two threads don’t always mesh perfectly, but the script juggles them with sufficient dexterity to make for a film that effectively dramatizes the clash between different eighteenth-century theories of rule while also providing a strong emotional element.

But though in the end its emphasis is on the doomed love of Struensee and Caroline Matilda, the real tragedy of the story lies in the fact that the doctor betrays his own beliefs by giving in to his attraction to the queen. In doing so, he surrenders his most fundamental Enlightenment belief, that a man must live his life in accordance with reason rather than surrendering to the pull of passion. One might note of the film that just as Enlightenment thought was eventually supplanted by Romanticism, “A Royal Affair” ultimately turns a narrative about a rational man into a sad story of doomed romance.

And it does so very nicely. It certainly looks right, with the Czech locations photographed by Rasmus Videbaek to serve as convincing stand-ins for Danish ones. And the cast is excellent. Mads Mikkelsen cuts a striking figure as Struensee, his long, dour face reflecting the doctor’s intelligence and his pained recognition of the danger his dalliance with Caroline poses to his governmental hopes. Alicia Vikander makes a attractive Caroline, who—in this telling, at least—is as progressive a thinker as her lover, her affection for him spurred when she borrows his copies of works by Rousseau and his ilk after her own have been summarily confiscated by the hidebound royal ministers, and becomes Struensee’s partner in pushing reform. (If their scenes together don’t quite set the screen afire, blame can be placed on the conventions of the time, which stifled too open an exhibition of emotion even in private.) And Mikkel Boe Foldgaard is touching as the erratic King Christian. Moving from childlike naivete to volcanic anger without missing a beat, he manages to generate sympathy for the mad monarch.

The supporting roles are equally well filled. Trine Syrholm is an imperious Queen Juliane and David Dencik appropriately loathsome as Guldberg, the primly pious minister who opposes Struensee at every turn. Thomas Gabrielsson and Cyron Melville are also fine as Rantzau and Brandt, the dissolute noblemen who initially induce Struensee to seek the post of court physician, only to come to very different ends—Rantzau turning against the doctor for personal reasons while Brandt suffers execution along with him.

“A Royal Affair” covers an episode in eighteenth-century European history that will probably be unknown to almost everybody who doesn’t specialize in the period (and Danes, presumably). But though it deals with what’s basically a historical footnote—an early Enlightenment experiment that failed—the film brings it to life with elegance and skill, if not perhaps the red-hot passion it’s aiming for.