What's Up With the Ending?
After all of that, the dude found at Sha Ka Ree is revealed to be a con artist—it's like The Wizard of Oz all over again. This guy behind the curtain blasts the crew of Enterprise after they dare question his divinity, revealing in the process that he tricked Sybok into coming there to break him out of his planetary prison. Devastated by this deception, Sybok sacrifices himself in an attempt to stop the impostor.
These events coincide with the Klingon assault on Enterprise. While Kirk battles the impostor on the planet, Spock negotiates a truce with the Klingons and enlists their help in saving Captain Kirk's life. It's a surprising twist as the Klingon captain Klaa spent most of the film trying to kill the man he's now rescuing.
With its climax achieved, the film ends with a big party. The guests include the crew of Enterprise, Klaa's posse, the colonists from Nimbus III, and even the three ambassadors. Scotty gloriously comments that he "never thought" he'd be kicking back brews "with a Klingon."
While this party is obviously played as a joke, it also represents the unity reached between these warring factions. After all, that was the original purpose of Nimbus III, right? To usher in a new era of peace among the races of the galaxy? Although that goal might not have been achieved in the way its creators expected, the crew of Enterprise has somehow managed to yank victory from the jaws of defeat.