It was Ansem(Xehanort's Heartless). He told Riku that his heart was weaker than Sora's and that was why he lost. He offered Riku the ultimate dark power, and possessed him. Afterwards, he created the Dark Keyblade from the current Princesses of Heart. Maleficent fought Sora and his friends, but lost. Riku came and revealed the power of the keyblade: to unlock people's hearts. He tested it on Maleficent, and she turned into a giant dragon, which Sora defeated. Facing Riku, he revealed Kairi has lost her heart and he needs to unlock it to unleash her final power. He tells Sora that her heart is within him, and proceeds to try and kill him. Through Kairi's voice, Sora finds the courage to resist the Seeker of Darkness and defeats him.

Well, that's the long story. So, Xehanort's Heartless came, mocked Riku's weakness, and then possessed him. He made this keyblade that can release hearts and used it on Maleficent. Later, he told Sora that Kairi's heart was within him and tried to release it, but failed.

FQ.