IMAP (Internet Message Access Protocol) is the protocol a mail client uses to read and manage messages directly on the server, keeping folders as well as read and flagged states in sync across all of a user's devices.
The client connects to the mail server over TCP (usually port 993 with encryption) and works with messages without downloading them in full: it requests the folder list and headers, and fetches a message body only when you open it. The mail itself stays on the server, so a phone, a laptop and the web interface all show the same inbox. The client finds the server address through DNS, while the domain's MX record defines the route for incoming mail.
The three mail protocols solve different problems:
So in practice IMAP and SMTP work as a pair: the former pulls incoming mail from the server, the latter sends outgoing mail.