Few directors have given me more pleasure over the past 40 years than Woody Allen, so it is a great relief to see him emerge after a fallow period of disappointments and disasters with his best film since Everyone Says I Love You in 1996. Midnight in Paris is a cinematic soufflé that rises to perfection, a wry, funny, touching picture, pursuing some of his favourite tropes and themes but with sufficient asperity to give a sting to the nostalgia it embraces. Standing in for Allen himself and dressed similarly in plaid shirt and khaki trousers, Owen Wilson plays Gil, a youngish Hollywood screenwriter and would-be novelist best known for his skills at rewrites, a diffident, humorous man with a great respect for high culture and a love of popular art but deeply suspicious of pretension and academic condescension. He's visiting Paris with his egocentric social-climbing fiancee, Inez (Rachel McAdams), and her wealthy, neo-xenophobic parents.

The opening montage of Paris is a romantic dream of the City of Light that recalls the magic monochrome New York that accompanies Gershwin's "Rhapsody in Blue" at the beginning of Manhattan or the seasonal montages on New York that introduce the four chapters of Everyone Says I Love You. It's the Paris of Gil's dreams, the movable feast enjoyed in the 1920s by Hemingway and Fitzgerald, whose company he aspires to in his imagination. His affectingly naive attitude to the past, however, is ridiculed by his fiancee and her patronising academic friend (Michael Sheen), a blood brother to the arrogant intellectual who lectures his date about Marshall McLuhan in the cinema queue in Annie Hall. One night Gil is walking the streets of Montmartre, more than slightly drunk, when a clock rings out the chimes of midnight. A bunch of rowdy American revellers in a vintage, chauffeur-driven Peugeot stop, drag him into the car and take him to a party. Gradually it dawns on him he's been transported back to the 1920s and is in the company of Gertrude Stein (Kathy Bates) and the writers she dubbed the Lost Generation – Hemingway, Zelda and Scott Fitzgerald, Djuna Barnes – along with Cole Porter, and their European friends, Picasso, Dalí and Buñuel. Each night at the witching hour he's drawn back into this lost world of shared, competitive artistic endeavour, becoming the confidant and drinking companion of the arrogant Hemingway, the apt pupil of the peremptory Stein, the saviour of the troubled Zelda from suicide in the Seine, the provider of plots for Buñuel.

Some years ago in The Moderns, Alan Rudolph tried to recreate the expatriate Parisian literary scene of the 1920s but ended up with an embarrassingly unconvincing satire. Here, Allen gets the tone exactly right, simultaneously avoiding and knowingly mocking the kind of historical pastiche Max Beerbohm was sending up in the celebrated stage direction to his Renaissance playlet Savonarola Brown: "Enter Boccaccio, Benvenuto Cellini and many others making remarks highly characteristic of themselves." Through skilful casting (the work of Juliet Taylor), affectionate humour and clever writing, Allen suggests that what we are seeing is the essence of these celebrated figures as filtered through the imagination of the wide-eyed Gil. Younger moviegoers may think of Back to the Future or Groundhog Day when they see this film. Allen's admirers are likely to compare it with his masterly Purple Rose of Cairo where a blue-collar housewife is courted by a movie star who steps out the escapist film she's watching to join her in Depression New Jersey. I think it likely that Allen has also been influenced by Victor Sjöström's silent Swedish masterpiece, The Phantom Carriage, his idol Ingmar Bergman's favourite movie, which centres on a ghostly coach going around town at midnight picking up the dead.

Allen cleverly balances past and present by giving Gil two alternative women to the irritating fiancee, one in the 1920s in the form of Adriana (Marion Cotillard), who has been model and mistress to Modigliani, Braque and Picasso, and the other a young antique dealer Gabrielle (Léa Seydoux) in a Parisian flea market. Adriana is discontented with the 1920s and longs for la Belle Epoque, which in a delightful sequence she visits with Gil to meet Toulouse-Lautrec at the Moulin Rouge. They discover, however, that Toulouse-Lautrec's drinking companions, Degas and Gauguin, look back nostalgically to the Renaissance as the true golden age. Gabrielle, on the other hand, who shares Gil's love of Cole Porter, is happy to live in the present while cherishing the past.

There is a clear parallel between the narrow, censorious, philistine world of Prohibition America that Hemingway and co were escaping in the 1920s and the repugnant US of George Bush represented by Gil's prospective parents-in-law. They despise what Donald Rumsfeld sneered at as "Old Europe" and support the Tea Party movement, and Allen does not spare them. This is the first time, I believe, that that party has been mentioned in a feature film.

Recent Allen films have tended towards the perfunctory, often looking like a succession of clumsy first takes. In Midnight in Paris he is relaxed and confident. The rhythms of the editing are perfect. The framing and grouping of the characters is comfortable. The actors are relaxed and confident in their movements. The boyishly bewildered, sheepishly vulnerable all-American charm of Owen Wilson has never been better used. Working in conjunction, the cinematographer Darius Khondji, the production designer Anne Seibel and the costume designer Sonia Grande have done a splendid job in giving the film distinct textures for its three different periods. The recreation of Gertrude Stein's apartment is a little gem, and when Kathy Bates sits beneath Picasso's famous portrait of Stein she looks at home.