Twenty-year-old Will Hunting (Matt Damon) of South Boston is a self-taught, genius-level intellect, though he works as a janitor at the Massachusetts Institute of Technology and spends his free time drinking with his friends, Chuckie (Ben Affleck), Billy (Cole Hauser) and Morgan (Casey Affleck). When Professor Gerald Lambeau (Stellan Skarsg책rd) posts a difficult mathematics problem 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. Lambeau chances upon Will solving the problem but Will flees the scene. That night at a bar, Will meets Skylar (Minnie Driver), a British student about to graduate from Harvard, who plans on attending medical school at Stanford and gives Will her phone number before leaving.
The next day as Will and his friends fight a gang at the basketball court, Police arrive and arrest Will. Lambeau visits his court appearance and notices Will's intellect in defending himself. He arranges for him to forgo jail time if he agrees to study mathematics under Lambeau's supervision and participate in therapy sessions. Will tentatively agrees, but treats his first few therapists with contempt and mockery. His refusal to open up is met with staunch defiance by the various therapists, who each refuse to deal with Will further. In desperation, Lambeau calls on Dr. Sean Maguire (Robin Williams), his estranged and much more grounded college roommate, who now teaches psychology at Bunker Hill Community College. Unlike other therapists, Sean actually challenges Will's 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 game six 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, after which his wife died 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 rundown neighborhood. Will also challenges Sean to take an objective look at his own life, since Sean cannot move on from his wife's death.
Lambeau sets up a number of job interviews for Will, but Will scorns them by sending Chuckie as his "chief negotiator", and by turning down a position at the National Security Agency with a scathing critique of the agency's moral position. Skylar asks Will to move to California with her, but he refuses and tells her he is an orphan, and that his foster father physically abused him. Will breaks up with Skylar, and later 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 walks in on a heated argument between Sean and Lambeau over his potential. Sean and Will share and find out that they were both victims of child abuse. Sean helps Will to see that he is a victim of his own inner demons and to accept that it is not his fault. Sean comforts Will as he cries over twenty years of trauma. Will decides to accept one of the job offers arranged by Lambeau. 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 twenty-first birthday, he decides to pass on his job offers and drive to California to reunite with Skylar. Sometime later, Chuckie goes to Will's house to pick him up, only to find that he is not there, much to his happiness. Sean comes out of his house and finds a letter from Will in his mailbox, which, much to his pleasure, tells him that Will is going to see Skylar. During the ending credits, Will's car is seen driving on the highway to California.

Question: How did Sean meet his wife?
Answer: By giving up his ticket to the world series.