The best strategy for collision avoidance under emergency conditions is to maximize wrt the controls the timewise minimum distance between the host ship and the intruder ship. In a restricted waterway area, two main constraints must be satisfied: the lateral deviation of the host ship from the original course is to be contained within certain limits; the longitudinal distance covered by the host ship is to be subject to a prescribed bound. At the maximin point of the encounter, the time derivative of the relative distance vanishes; this yields an inner boundary condition (orthogonality between the relative position vector and the relative velocity vector) separating the main phases of the maneuver: the avoidance and recovery phases. In this way, the optimal trajectory problem (a Chebyshev problem) can be converted into a Bolza problem with an inner boundary condition. Numerical solutions are obtained via the multiple-subarc sequential gradient-restoration algorithm (SGRA). Because the optimal trajectory is not suitable for real-time implementation, a guidance scheme approximating the optimal trajectory in real time is to be developed. For ship collision avoidance, the optimal trajectory results show that the rudder angle time history has a bang-bang form characterized by the alternation of saturated control subarcs of opposite signs joined by rapid transitions. Just as the optimal trajectory can be partitioned into three phases (avoidance phase, recovery phase, steady phase), a guidance trajectory can be constructed in the same way. For the avoidance and recovery phases, use of decomposition techniques leads to an algorithm computing the time lengths of these phases in real time. For the steady phase, a feedback control scheme is used to maneuver the ship steadily. Numerical results are presented.