As the legends say, Asmodeus threw Solomon away from his kingdom after the temple was built. He then took the king's place until the latter regained his rule, causing Asmodeus to escape.