In 1985, near the city of Boston, Massachusetts, John Bennett was a lonely child who dearly wished for his new Christmas gift, a large teddy bear named Ted, to come to life to be his friend. That wish coincided with a falling star and Ted became a fully mobile sentient being. John's parents (Alex Borstein and Ralph Garman) got over the shock, word of the miracle spread, and Ted was briefly a celebrity.
In 2012, John (now played by Mark Wahlberg) and Ted (now voiced and motion captured by Seth MacFarlane), now living in the South End neighborhood of Boston, are still staunch, if immature, companions enjoying a hedonistic life even while John is pursuing a 4-year-long relationship with a level-headed office worker, Lori Collins (Mila Kunis). As the fourth anniversary of their relationship approaches, Lori hopes to marry John, but she feels he can't move ahead with his life with Ted around, who has become a vulgar, obnoxious wastrel. John is resistant to making his lifelong companion leave, but he is finally persuaded that night to act when the couple discover Ted at home with four prostitutes, one of whom has defecated on the floor during a game of Truth or Dare.
John finds Ted his own apartment and a job at a grocery store, where his grossly irresponsible behavior on the job manages to both get him promoted and acquainted with the superficial co-worker Tami-Lynn (Jessica Barth), who gets easily irritated by Lori who is shocked at her anger. Regardless, Ted and John still spend most of their time together, which frustrates Lori when she discovers John has been skipping work to do so while using her for his excuses. Meanwhile, a crazed loner named Donny (Giovanni Ribisi), who idolized Ted as a child, shows interest in possessing him for his brutishly destructive son, Robert (Aedin Mincks). Things start to come to a head when Lori and John are invited to a party put on by Lori's lecherous manager, Rex (Joel McHale), and Ted lures John away to a wild party at his apartment with the offer to meet Sam J. Jones (playing himself), the star of their favorite movie, Flash Gordon. Although John arrives with the intention of spending only a few minutes, he gets caught up in the occasion which gets completely out of control, with Sam J. Jones persuading John and Ted to snort cocaine and Ted singing karaoke and eventually getting beaten-up by a duck. Eventually, Lori discovers John there and breaks up with him in a rage. At that, John blames Ted for ruining his life and tells him to stay away.
Eventually, Ted and John confront each other about their ruined friendship in John's hotel room and have a destructive brawl, but soon manage to reconcile. To repair John's relationship with Lori, Ted arranges with an old lover, singer Norah Jones (playing herself), to help by having John express his love for Lori with a song during her concert, being held at the Hatch Shell. Although John's performance proves an embarrassment, Lori is touched by the attempt while repelled by Rex's sneering. Later, Ted meets Lori at her apartment and explains that he was responsible for John's lapse; he offers to leave them alone forever if she goes to at least speak with him. Lori is persuaded, but moments after she leaves, Ted is kidnapped by Donny and taken to his house to function as Robert's victim.
Ted manages to distract Robert and reach a phone to contact John, but is soon recaptured. Realizing that Ted is in danger, John and Lori manage to find Donny's residence and chase him and Robert to rescue Ted. The chase leads to Fenway Park, where John manages to knock out Robert, but during the chase Ted is damaged and falls onto the field, torn completely in half. A police car arrives, forcing Donny to flee. As John and Lori gather his stuffing, Ted relays his wish that John be happy with Lori, as the magic that gave him life fades away.
Unable to accept his best friend's death, Lori and John return to her apartment to attempt to repair him, but it proves useless. That night, Lori wakes up and quietly makes a wish on a falling star. The next morning, Ted is magically restored and the trio fully reconcile with Ted, who encourages John and Lori to resume their relationship.
With that resolution, John and Lori are married and Ted comfortably accepts having a life of his own, with his misbehavior getting him somehow promoted to grocery store manager. John and Lori are married in a ceremony presided over by Sam Jones. Rex gives up his relationship with Lori after she marries, so he undergoes a deep depression, and dies of Lou Gehrig's disease (which John wished he would die from earlier in the film). Sam Jones attempts to restart his career by moving into a studio apartment with Superman Returns star Brandon Routh. Donny is arrested for the kidnapping of Ted, but the charges are dropped because they sound too stupid. Robert hires a personal trainer to lose a large amount of weight and eventually becomes Taylor Lautner.