I think this may be the Earthsea miniseries.
With the help of Ogion, Ged confronts the Gebbeth and attempts to drown him using a rock, however, it escapes with Ged's likeness and voice. Ged's impersonator becomes a murderer, and Vetch, a magus himself, chases Ged until he realizes Ged is not possessed by the Gebbeth and they decide to hunt it together.
They are attacked by the dragon, Orm Embar, but Ged uses the dragon's true name to bind him and ask three questions. He wastes his first question, but with his second, he learns the Gebbeth's location. The dragon tells him where to find the two pieces of the Amulet of Peace, which when reunited would save Earthsea, but Ged could have asked the true name of the demon.
Here's a clip at the relevant part.
In case that gets taken down, here's a screenshot with them and the dragon around that point: