You're probably thinking of
Little Nemo: Adventures in Slumberland (1989) It's about a little boy named Nemo who has bad dreams when he eats pie before dinner. He promises him mom he wont eat any more pie and when he goes to sleep he has what starts off as a pleasant dream about a place called slumberland where he is loved by everyone, especially by King Morpheus and his daughter. He becomes the prince of slumberland and makes a promise to the king never to open the door with the dragon symbol (the same as the symbol on the Key King Morpheus gives him) However like his promise to his mother he breaks this one too. When he opens the forbidden door he unleashes the Nightmare King who captures King Morpheus by sending a strong black slime that quickly envelops the king and takes him to Nightmareland (this is the part where Nemo "wakes up" and walks downstairs to find his kitchen door glowing and when he opens it their is a flood behind the door that takes him back to slumberland. All in all Nemo rescues the King, saves slumberland, and Marries the Princess. This was my all time favorite movie as a kid. The part I remember the most and will never forget is when Nemo is trying to defeat the Nightmare King He holds up the royal septor and screams "PAJAMA PAJAMA PAJAMA!!!!" anyways I'm pretty sure this is the movie you're thinking of and it's definitely worth watching again.