From the Super Mario Wiki
When King Koopa and Kooky von Koopa planned to take over Sky Land with their Kooper-Dooper Raiser-Upper, they kidnapped Emperor Ed, and put him in a jail cell on the Doom Ship. Ed tried to threaten the two Koopas, but was ignored and intimidated by his Rocky Wrench jailer. After King Koopa turned up the power of the Kooper-Dooper Raiser-Upper, the Doom Ship began to shake and Emperor Ed fell out off the porthole.
Luckily, Ed fell on a floating bed, which promptly falls to the ground. Ed then jumps out of the bed, accidentally landing on Toad. The Mario Bros. promise to help Emperor Ed, and go to confront the Koopas after dropping him off at his castle. Ed and his subjects protested against King Koopa after he had declared himself the ruler of Sky Land. King Koopa and Kooky were defeated shortly afterwards by the Mario Bros., and Emperor Ed and his subjects returned to peace.