By Deborah Cole
In a stunning upset, the nine-member jury led by Spanish director Pedro Almodovar and including Hollywood stars Jessica Chastain and Will Smith awarded the trophy to the movie's director, Ruben Ostlund.
"Oh my God, oh my God!" Ostlund shouted from the stage after besting a raft of favourites for one of global cinema's most coveted honours with a rare comedy.
In a 70th edition marked by raging debate over sexism in the movie industry, Sofia Coppola became only the second woman in history to win best director for her battle-of-the-sexes thriller "The Beguiled" with Nicole Kidman and Colin Farrell.
Kidman, who appeared in four different projects at the French Riviera festival, accepted a special anniversary award from the jury with a video message from Nashville, Tennessee.
Three-time Oscar nominee Joaquin Phoenix nabbed best actor for his turn as a hammer-wielding hitman in "You Were Never Really Here".
"Any work that I did was linked to the work of Lynne Ramsay," the film's British director, Phoenix said, before apologising for his tuxedo-and-trainers look at the gala ceremony.
"I don't wear leather," the committed vegetarian explained.
Diane Kruger clinched best actress for her first film role in her native German as a devastated mother who has lost her husband and son in a neo-Nazi terror attack, in Fatih Akin's "In the Fade".
"I cannot accept this award without thinking of everyone who has been touched by an act of terrorism... you have not been forgotten," said a visibly moved Kruger.
Chastain called it "disturbing" that there had not been more meaty female roles among the 19 contenders for the Palme d'Or. Only three of the films were made by women.
- 'So much courage' -
Greece's Yorgos Lantimos shared best screenplay prize with Ramsay for "The Killing of a Sacred Deer", an icy thriller set in a wealthy American suburb and also starring Kidman and Farrell.
The runner-up Grand Prix went to a picture that was widely tipped to win, the moving French drama "120 Beats Per Minute" about the radical activists who helped shame the world into action on Aids.
"This film is an homage to those who died but also those who survived and are still alive, who had so much courage," said the movie's director, former ACT UP member Robin Campillo.
Fighting back tears, Almodovar told reporters that the "democratic jury" had fiercely debated the winners.
"I loved the movie. I couldn't love it more. I was touched since the very beginning until absolutely the end, and after the end," he said.
"Loveless" by Andrey Zvyagintsev, a wrenching drama about moral rot gnawing at Russian society under Vladimir Putin, took the third place jury prize.
- 'Very funny' -
"The Square", coming in at two hours and 20 minutes, is an often hilarious satire exploring creative liberty, free speech and the blurred lines between the sexes.
Danish actor Claes Bang plays a museum director and divorced father of two young daughters who gets robbed in broad daylight in the city centre.
In the aftermath, he's forced to check his privilege, class presumptions and liberal political beliefs against a reality that rarely mirrors the rarified world of high culture.
The title refers to a conceptual art project in which museum visitors are invited to enter a "sanctuary of trust and caring", a small utopia in the middle of a flawed society.
The movie features Elisabeth Moss ("Mad Men") and Dominic West ("The Wire") in small roles viciously lampooning the self-important art world.
One set-piece featuring a wild, bare-chested man performing as an ape wreaking havoc at a posh gala dinner has already entered festival legend.
Almodovar hailed its themes as "completely contemporary".
"Such a serious subject is treated with such incredible imagination -- it's very funny," he said.
Cannes' 12 days of screenings and celebrity-packed soirees -- which were somewhat muted by the Manchester bombing -- were marked by unprecedented anti-terror measures and a raging row over how technology is shaping the future of the movie industry.
Netflix had two movies in competition for the first time but faced blowback from critics who argued that online streaming is destroying cinema distribution and with it the magic of the big-screen experience. The company left Cannes empty-handed.