Though Will Hunting (Matt Damon) has a genius-level intellect, eidetic memory and a profound gift for mathematics, he works as a janitor at MIT and lives alone in a sparsely-furnished house in a rundown South Boston neighborhood. An abused foster child, he subconsciously blames himself for his unhappy upbringing and turns this self-loathing into a form of self-sabotage in both his professional and emotional lives.
In the first week of class, Will solves a difficult graduate-level problem taken from algebraic graph theory that Professor Gerald Lambeau (Stellan Skarsgård), a Fields Medalist and combinatorialist, leaves on a chalkboard as a challenge posed to his students, hoping someone might find the solution by the end of the semester. When it is solved quickly and anonymously, Lambeau posts a much more difficult problem—one that took him and his colleagues two years to prove. When Lambeau chances upon a mere janitor writing on the board, Lambeau chases him away. However, when Lambeau returns to the board, he is astounded to find the correct answer there. He then sets out to track Will down.
Meanwhile, Will attacks a youth who had bullied him 15 years ago in kindergarten, and he now faces imprisonment after attacking a police officer who was responding to the fracas. Realizing Will has enormous potential, Lambeau goes to Will's trial and intervenes on his behalf, offering him a choice: either go to jail, or be released under Lambeau's personal supervision to study mathematics and see a therapist. Will chooses the latter, even though he does not believe he needs therapy.
Will treats the first five psychologists Lambeau has him see with utter contempt. In desperation, Lambeau finally calls on Sean Maguire (Robin Williams), an estranged old friend and MIT classmate who happens to have grown up in the same neighborhood as Will. Sean differs from his predecessors in that he pushes back at Will and is eventually able to get past Will's hostile, sarcastic defense mechanisms. Will is particularly struck when Sean tells him how he gave up his ticket to see the Red Sox in Game 6 of the 1975 World Series (thus missing Carlton Fisk's famous home run) in order to meet and spend time with a stranger in a bar, who would later become his wife. This encourages Will to try to establish a relationship with Skylar (Minnie Driver), a young woman he had earlier met at a bar near Harvard University.
This doctor-patient relationship, however, is far from one-sided. Will challenges Sean to take a hard, objective look at his own life. Sean has been unable to deal with his beloved wife's premature death from cancer two years before.
Meanwhile, Lambeau pushes Will so hard that Will eventually refuses to go to the job interviews that Lambeau arranges for him. Will accidentally walks in while Lambeau and Sean are furiously squabbling about the direction of his future.
Skylar asks Will to move to California with her, where she will begin medical school at Stanford. Will panics at the thought. When Skylar expresses sympathy about his past, it triggers a tantrum and Will storms out of the dorm. He shrugs off the work he has been doing for Lambeau as "a joke". Lambeau begs Will not to throw it all away, but Will walks out.
Sean points out that Will is so adept at anticipating future failure in his romantic relationships, that he either allows them to fizzle out or deliberately bails, so he can avoid the risk of emotional pain. When Will refuses to give an honest reply to Sean's query about what he wants to do with his life, Sean shows him the door. Will tells his best friend Chuckie (Ben Affleck) that he wants to be a laborer for the rest of his life. Chuckie becomes brutally honest with Will: he feels it's an insult for Will to waste his potential, and that his greatest wish is to knock on Will's door one morning and find he isn't there.
Will goes to another therapy session, where he and Sean share that they were both victims of child abuse. Finally, after much self-reflection, Will decides to cease being a victim of his own inner demons and to take charge of his life.
When his buddies present him with a rebuilt Chevrolet Nova for his 21st birthday, he decides to go after Skylar, setting aside his lucrative corporate and government job offers. Will leaves a brief note for Sean, using one of Sean's own quips, "I had to go see about a girl." Chuckie discovers that Will has finally gone. Will is then shown starting for California for a new beginning with Skylar.