TLS ensures data integrity by employing cryptographic hash functions during the handshake process and for generating the message authentication code (MAC). These mechanisms help detect any accidental modifications or malicious tampering during transmission.