“Midnight in Paris,” Woody Allen’s charming new film, imagines what would happen if that wish came true. It is marvelously romantic, even though — or precisely because — it acknowledges the disappointment that shadows every genuine expression of romanticism. The film has the inspired silliness of some of Mr. Allen’s classic comic sketches (most obviously, “A Twenties Memory,” in which the narrator’s nose is repeatedly broken by Ernest Hemingway), spiked with the rueful fatalism that has characterized so much of his later work.

Nothing here is exactly new, but why would you expect otherwise in a film so pointedly suspicious of novelty? Very little is stale, either, and Mr. Allen has gracefully evaded the trap built by his grouchy admirers and unkind critics — I’m not alone in fitting both descriptions — who complain when he repeats himself and also when he experiments. Not for the first time, but for the first time in a while, he has found a credible blend of whimsy and wisdom.

Paris, golden and gray, breezy and melancholy, immune to its own abundant clichés and gorgeously shot by Darius Khondji, certainly helps. So does a roster of droppable names that includes recent Oscar winners, the current first lady of France and a pantheon of credibly impersonated artistic immortals. Was that Carla Bruni? Why yes, it was. And that was Salvador Dalí too. (Dalí is played by Adrien Brody. The multitalented Mme. Sarkozy plays a tour guide at the Musée Rodin.)

Owen Wilson, a tall, laid-back iteration of the familiar Allen persona, is Gil, a perpetually dissatisfied Hollywood screenwriter trying to reinvigorate his youthful dreams of literary glory. He’s at work on a novel about “a guy who owns a nostalgia shop” and at the same time indulging in the virtual time travel that Paris affords a certain kind of visitor. You can sit at a table where Hemingway drank wine — or Degas or Baudelaire or even Diderot, if you prefer — and imagine that they just stepped out to take the air.

But Gil, by means that Mr. Allen wisely leaves unexplained, is transported back into his chosen Parisian golden age, more or less reversing the process that brought Emma Bovary to Manhattan in his short story “The Kugelmass Episode” or Tom Baxter down from the movie screen in “The Purple Rose of Cairo.” As Gil sulks one night at a quiet crossroads, an antique roadster comes rattling by, and he is swept off to a soirée by none other than Scott and Zelda Fitzgerald (Tom Hiddleston and Alison Pill).

The process repeats itself each night, granting Gil V.I.P. access to a nonstop Lost Generation party. It would be the height of bad manners to list every cultural hero he runs into — it’s a remarkably comprehensive catalog of the varieties of modernism percolating in Paris between the wars — but he makes the requisite pilgrimage to visit Gertrude Stein (Kathy Bates), who graciously agrees to read his manuscript. He also develops a crush on Adriana (Marion Cotillard), who has been keeping company with Hemingway (Corey Stoll) and Picasso (Marcial Di Fonzo Bo) and who wishes she could exchange the drab Paris of the ’20s for the Belle Époque, when things were really happening.

Adriana’s sighing dissatisfaction with her own era mirrors Gil’s. Back in the daylight world of 21st-century Paris, he must contend with a materialistic fiancée (a superbly speeded-up Rachel McAdams; her vulgar, moneyed parents (Kurt Fuller and Mimi Kennedy); and an insufferable pedant named Paul (Michael Sheen). Paul’s habit of prefacing every show-offy bit of data with “if I’m not mistaken” is a sign that, in the ways that count, he is. He is another classic Woody Allen type, the know-it-all pseudo-intellectual, and as such the obvious foil for Mr. Wilson’s passionate, self-deprecating schlemiel. If Paul ever met T. S. Eliot, he would spout revised footnotes for “The Waste Land.” For his part, Gil cries out, “Prufrock is my mantra!”

Let’s not go there, you and I. Unless I’m mistaken, “Prufrock” is a statement of the very ennui — the perception of a diminished world unable to satisfy a hungering sensibility — that afflicts Gil. Mr. Allen’s treatment of this condition is gentle and wry. He can hardly be unaware that he himself is, for much of his audience, an object of nostalgic affection, much the way Cole Porter, among others, is for Gil, his alter ego. That a shared love of Porter’s music allows Gil to forge a connection in the present (and conceivably the future) with a young Parisian woman (Léa Seydoux) is a sign that his fetishizing of bygone days has been based on a mistake. Paris is perpetually alive, not because it houses the ghosts of the famous dead but because it is the repository and setting of so much of their work. And the purpose of all that old stuff is not to carry us into the past but rather to animate and enliven the present.

Mr. Allen has often said that he does not want or expect his own work to survive, but as modest and lighthearted as “Midnight in Paris” is, it suggests otherwise: Not an ambition toward immortality so much as a willingness to leave something behind — a bit of memorabilia, or art, if you like that word better — that catches the attention and solicits the admiration of lonely wanderers in some future time. Ah, did you once see Woody plain? How strange it seems, and new.