Could you be thinking of the 1986 film, Starchaser: Legend of Orin?
In the future on a planet named Trinia, human slaves have lived underground for millennia mining crystals for a "god" named Zygon and his robot minions. One day Orin, a young miner, finds a jeweled sword embedded in the rocks. Hopps, grandfather of Orin's girlfriend Elan, recognizes the sword and gives his life to save Orin and keep the sword a secret. When Orin later takes the sword into his hands, it ascends into the air and buries itself in the cavern's floor. A projection of an old man appears from the blade, telling those present that above the caverns is a "magnificent universe" that the people may find (they have been told that above the cavern is "Hell"). The blade then disappears, leaving only the hilt.
Orin digs a tunnel to the surface of Trinia, where he is later captured by Man-Droids, a group of decaying half-organic, half-robotic beings who intend to tear him apart and use his body parts to replace their own. Unexpectedly, his sword's hilt produces what is apparently an invisible blade, killing two of the Man-Droids and helping Orin escape. Orin subsequently runs into a human smuggler named Dagg Dibrimi, who takes Orin (whom he dubs "Water Snake" for his outrageous tale about human slaves in the mines) along on his journey to smuggle crystals. Eventually, Dagg seizes a load of crystals from a hovering freighter, but is driven away by Zygon and his robotic guards. During the fight, Dagg seizes a Fembot named Silica and uses it as a shield from laser blasts. Subsequently, re-programmed by Dagg, Silica becomes attached to him. At the same time a mysterious "Starfly" appears and attaches itself to Orin.
Upon having woken and met Aviana, Orin tells her his story, whereupon Aviana's computer reveals that the hilt has historically been used by a group of legendary guardians called the Ka-Khan to vanquish threats to humanity. Among these threats was a tyrant called Nexus, after whose defeat the hilt vanished until Orin's discovery of it. Aviana takes Orin to Trinia, where he again faces Zygon. Orin attempts to kill Zygon for Elan's death and thereby exposes him as a robot. Zygon then reveals that he is Nexus, seeking again to rule over humanity with his army of robots. Zygon takes Orin's hilt and begins to co-ordinate the attack, while Orin and Aviana are imprisoned in the cell block wherein Dagg is also captive. Just as Orin and Aviana confess their feelings toward one another, Aviana is taken aboard Zygon's flagship as a hostage. Orin is again approached by the Starfly, who brings him the hilt, which he uses to free himself and Dagg. They enter Zygon's flagship and take control of it, using it (again aided by the Starfly) to destroy the enemy fleet. They are rejoined by Silica, who has restored the Starchaser.
Above, Silica mistakenly fires a laser blast from the Starchaser into the accumulated crystals, causing them to explode and triggering a chain reaction which threatens to collapse the mines. Orin uses the hilt to open a fissure by which his people ascend to Trinia's surface, where Orin uses his new-found power to heal Calli of his blindness and Dagg, Silica, and Aviana join them. Moments later, several Starflies reveal themselves to be the spirits of the past Ka-Khan, including the elder man of the hilt's projection. They invite Orin to join them; but he refuses for the time being in favor of living with his friends. Thereafter the other Ka-Khan leave him to merge with the stars.
It's the governor's daughter, not a princess, but it otherwise matches.