We present a method for performing evasive motions with a humanoid robot. In the considered scenario, the robot is standing in a workspace, when a moving obstacle (e.g., a human, or another robot) enters its safety area and heads towards it; the humanoid must plan and execute in real-time a maneuver that avoids the collision. The proposed method goes through several conceptual steps. Once the entrance of the moving obstacle in the safety area is detected, its approach direction relative to the robot is determined. On the basis of this information, a suitable evasion maneuver represented by footsteps is generated. From these, an appropriate trajectory is computed for the Center of Mass of the humanoid. Finally, joint motion commands are generated so as to track such trajectory. All computations make use of closed-form expressions and are therefore suitable for real-time implementation. The proposed approach is validated via simulations and experiments on a NAO humanoid. The possibility of adapting the basic method so as to be used in a replanning framework is also investigated.