Here’s a whimsical ending not even Woody Allen would’ve written: him winning a fourth Oscar more than 20 years on.

Allen took the best original screenplay for “Midnight in Paris'” at Sunday’s Academy Awards, adding to three previous wins.

The most recent was more than two decades ago, as the writer-director nabbed original screenplay for “Hannah and her Sisters” in 1987. He won screenplay and director for “Annie Hall” in 1978.

To no one’s surprise, Allen did not attend. Presenter Angelina Jolie accepted on his behalf.

Allen came in with a 10-nomination losing streak, the last being an original screenplay nod for his 2005 pic “Match Point.” Sunday night’s win provides further evidence of the significance of “Midnight in Paris” in Allen’s oeuvre: Besides the screenplay win (and his first best pic-nommed film since “Hannah”) “Midnight in Paris” was also Allen’s highest-grossing pic at the box office, grossing $148 million worldwide.

“Midnight in Paris” won over “The Artist” by Michel Hazanavicius, “Bridesmaids” by Annie Mumolo & Kristen Wiig, “Margin Call” by J.C. Chandor and “A Separation” by Asghar Farhadi.