Emotionally withdrawn Joel Barish (Jim Carrey) and dysfunctional free spirit Clementine Kruczynski (Kate Winslet) strike up a relationship on a Long Island Rail Road train from Montauk. They are inexplicably drawn to each other, despite their radically different personalities.
Although they apparently do not realize it at the time, Joel and Clementine are in fact former lovers, now separated after having spent two years together. After a nasty fight, Clementine hired a New York firm – Lacuna, Inc. – to erase all memories of their relationship. (The term "lacuna" means a gap or missing part. Lacunar amnesia is a gap in one's memory about a specific event.) Upon discovering this, Joel was devastated and decided to undergo this same procedure himself. However, while unconscious and having his memories of Clementine erased, he rebelled, realizing he wants to hold on to his memories of her after all.
Much of the film takes place in Joel's mind. As the memories are erased, Joel finds himself revisiting these past memories in reverse. Upon seeing happier times of his relationship with Clementine from earlier in their relationship, Joel struggles to preserve at least some memory of Clementine and his love for her. Despite Joel's efforts, the memories are slowly erased, with the last memory of Clementine telling him to "Meet me in Montauk".
In separate and related story arcs occurring during Joel's memory erasure, the employees of Lacuna are revealed to be more than peripheral characters. Mary (Dunst) turns out to have had an affair with the married doctor (Wilkinson) who heads the company, a relationship which she agreed to have erased from her memory when it was discovered by his wife.
Once Mary learns this, she steals the company's records and sends them to all of its clients. Joel and Clementine come upon these records just after having re-encountered each other on the train. They react with shock and bewilderment, given that they have no clear memory of having known each other, let alone having had a relationship and electing to have the memory erased. In the end, they reunite despite knowing that their past relationship, now erased, failed. Even though their prior relationship fell apart that they are willing to try again.