Article 25: Rights of protection of the coastal State

1. The coastal State may take the necessary steps in its territorial sea to
prevent passage which is not innocent.
2. In the case of ships proceeding to internal waters or a call at a port
facility outside internal waters, the coastal State also has the right to take the necessary steps to prevent any breach of the conditions to which admission of those ships to internal waters or such a call is subject.
3. The coastal State may, without discrimination in form or in fact
among foreign ships, suspend temporarily in specified areas of its territorial sea the innocent passage of foreign ships if such suspension is essential for the protection of its security, including weapons exercises. Such suspension shall take effect only after having been duly published.
Source :UNCLOS