You're looking at just one small part of the protocol. TLS, like any other communication protocol combines several cryptographic primitives to provide communications security. The algorithms used to secure the communication channel are described by a cipher suite, which combines a key exchange method (usually some form of Diffie-Hellman), an authentication method (usually a signature algorithm), a symmetric authenticated encryption method, and a hash algorithm which is used together with the authentication method. (This is the format of typical TLS 1.2 cipher suites. There are several variations which I won't go into here. TLS 1.3 uses the same building blocks but encodes the choice differently.)
The TLS protocol starts with a handshake where the client and the server set up a secure channel. For signature-based cipher suites, which is the most common case, the client and the server conduct a Diffie-Hellman key exchange, which lets them obtain a shared secret (the premaster secret). They then derive secret keys for authenticated encryption from this shared secret. An adversary observing the exchange cannot obtain the shared secret. However, an active man-in-the-middle can open a connection with the client and another one with the server. To prevent that, the server calculates a hash of the data exchanged during the handshake and signs it with its private key. The client calculates the hash of the data that it has exchanged and verifies the signature with the server's public key. If the two sides were talking to each other, they have seen the same data, so the signature is correct. If the two sides were each talking to a man-in-the-middle, they have seen different data, so the signature is incorrect and the client aborts the connection.
There are many different methods for authenticated encryption. In the old days (up to TLS 1.2), encryption was done with either a block cipher in CBC mode or the stream cipher RC4, and authentication of the data was done with HMAC. Since TLS 1.2, it is possible and preferred to use a proper AEAD construction such as a block cipher in GCM or CCM mode, or some other authenticated cipher (ChaCha20+Poly1305).
I've left out many parts and variants. For a more detailed overview of TLS, read How does SSL/TLS work?
.