From the Harry Potter wiki entry on Priori Incantatem:
"During a wand duel, a simultaneous spellcasting by both parties with twin wand cores will trigger an effect where both wands are linked through seperate threads of spell energy. The two wand holders then compete in a battle of wills, in which the loser's wand is forced to display in ghostly form the spells which had been cast by said wand, in order of most recent to least recent."
Harry won that duel via a superior will. The ghosts opted to distract Voldemort and the Death Eaters while Harry made for Cedric's body and the Cup. They weren't there to win him the wand duel.