Twenty-year-old Will Hunting (Damon) of South Boston is a self-taught, genius-level intellect with an eidetic memory, though he works simply as a janitor at the Massachusetts Institute of Technology, and spends his free time drinking with his friends Chuckie (Affleck), Billy (Cole Hauser), and Morgan (Casey Affleck). When Professor Gerald Lambeau (Skarsgård) posts a difficult problem taken from algebraic graph theory as a challenge for his graduate students, Will solves the problem anonymously, stunning both the graduate students and Lambeau himself. As a challenge to the unknown genius, Lambeau posts an even more difficult problem and chances upon Will solving it. Fearing he'll lose his sole means of (a meager) income, Will flees, and skips going into work the next day. That night, Will meets Skylar (Driver), a British orphan about to graduate from Harvard, who plans on attending graduate school at the Stanford University School of Medicine immediately after.
Assaulting a man who bullied him as a child, Will faces incarceration, but Lambeau arranges for him to forgo jail time if he agrees to study mathematics under Lambeau's supervision while simultaneously seeking behavioral health treatment with a therapist. Will tentatively agrees but treats his first few therapists with contempt; his refusal to open up is met with staunch defiance by the bourgeois mentality of the therapists, who each refuse to treat Will further. In desperation, Lambeau calls on Dr. Sean Maguire (Williams), his estranged—and much more grounded—college roommate, who now teaches psychology at Bunker Hill Community College. Unlike the other therapists, Sean actually challenges Will's weak defense mechanisms, and after a few unproductive sessions Will begins to open up.
Will is particularly struck by Sean's story of how he met his wife by giving up his ticket to the historic sixth game of the 1975 World Series after falling in love at first sight. Sean neither regrets his decision, nor does he regret the final years of his marriage when his wife was dying of cancer. This encourages Will to build a relationship with Skylar, though he lies to her about his past and is reluctant to introduce her to his friends or show her his run-down neighborhood. Will also challenges Sean to take an objective look at his own life, since Sean has been unable to move on from his wife's death.
Chafing under Lambeau's high expectations, Will makes a mockery of job interviews that Lambeau arranges for him. Will walks in on a heated argument between Sean and Lambeau over his future and it greatly upsets him. When Skylar asks Will to move to California with her, he panics and pushes her away, revealing that he is an orphan and that his foster father physically abused him. Skylar tells Will that she loves him, but he denies loving her and then leaves. He next storms out on Lambeau, dismissing the mathematical research he has been doing. Sean points out that Will is so adept at anticipating future failure in his interpersonal relationships that he deliberately sabotages them in order to avoid emotional pain. When Will refuses to give an honest reply about what he wants to do with his life, Sean shows him the door. Will tells Chuckie he wants to be a laborer for the rest of his life; Chuckie responds that it would be an insult to his friends for Will to waste his potential, and that his fondest wish is that Will should leave to pursue something greater. Will decides to accept one of the job offers arranged by Lambeau.
Sean and Will share that they were both victims of child abuse, and Sean helps Will to accept that the abuse he suffered was not his fault. Having helped Will overcome his problems, Sean reconciles with Lambeau and decides to take a sabbatical to travel the world. When Will's friends present him with a rebuilt Chevrolet Nova for his 21st birthday, he decides to pass on his job offers and drive to California to reunite with Skylar, which he mentions in a letter to Sean.