Lamport's algorithm for mutual exclusion uses timestamping of messages and request queues to provide a total ordering of requests for shared resources. Each process maintains a request queue and follows 5 rules: (1) the initiator sends a timestamped request to all processes, (2) other processes add the request to their queue and reply, (3) the initiator is allowed access when its request is at the front of all queues and it has received all replies, (4) the initiator releases the resource by sending a release message, and (5) processes remove the request from their queue upon receiving the release. The algorithm guarantees only one process can access the resource at a time and is deadlock-free due to the timestamp ordering.