From 1970's, legged robots have attracted much attention of many researchers. In spite of this, it has been regarded that dynamically stable walking is very difficult to be tackled for any types of legged robots. For a trot gait for quadruped walking robots, we have proposed "the sway compensation trajectory". This method utilizes a lateral, longitudinal, and vertical motion of a robot body to keep a zero moment point (ZMP) on a diagonal line between support legs. In this paper, we develop the sway compensation trajectory for a biped robot, and show that dynamically stable walking is realized. This method makes it quite easy to design stable ZMP and COG (center of gravity) trajectories, which have been regarded as a very complicated and delicate problem. The effectiveness of the proposed method is verified through computer simulations and walking experiments by a humanoid robot HOAP-1, and YANBO-3.