To close the WebSocket connection, call the 'close()' method on the WebSocket object. Optionally, you can also pass a status code and reason as parameters for a more detailed closing handshake.