In 1985, John Bennett (Brett Manley) is an 8-year-old boy who lives near Boston and is friendless as nobody will play with him. On the Christmas morning that year, John gets a teddy bear from his parents (Alex Borstein and Ralph Garman) as a Christmas present and names him "Teddy" (Zane Cowans). That night, John wishes Ted was alive so he can have a friend and his wish is granted by a falling star. The next morning, Ted comes to life, able to walk and speak, and with the mind of a human. At first both John and his parents are scared, but soon become overjoyed. Soon after, Ted becomes famous world-wide, but his fame is short-lived.
Twenty-seven years later in 2012, John (Mark Wahlberg) at 35 and Ted (Seth MacFarlane) are still best friends and live together in an apartment in Boston smoking marijuana and boozing while watching TV. John's other roommate and girlfriend of four years, Lori Collins (Mila Kunis) becomes annoyed that John is spending time with Ted and that he is acting like a child. After their dinner date one night, John and Lori discover that Ted invited female hookers for a party with one of them defecating on the carpet. John soon helps Ted get an interview at a local supermarket where he gets a job as a shop assistant and flirtingly befriends Tami-Lynn, another new employee. The pair are caught having sexual intercourse during their shift, but this only causes Ted to get promoted and keeps his job much to his annoyance. After a dinner-date which includes Ted and Tami-Lynn goes wrong, Lori admits to John that she knows he is still hanging out with Ted, even making excuses to leave work as a car rental assistant early. John promises to stop being with Ted.
A few nights later at a house party hosted by Lori's stalking boss Rex (Joel McHale) who has a crush on her, John gets a call from Ted that Flash Gordon star Sam J. Jones is in his new apartment. John, after some encouragement disobeys Lori and goes to see Sam at Ted's party, there Sam befriends the duo, before they have the time of their lives getting stoned, drunk and Ted singing karaoke. Lori though discovers John had betrayed her and tearfully dumps him. John angrily blames Ted for what happened and asks him to get out of his life. A week later, Rex asks Lori out on a date and she accepts, hoping to temporarily distract herself from heartache and finally get Rex to leave her alone. Ted finds out and visits the hotel room where John is staying to tell him about it. John accuses Ted of lying and says he wishes he got a Teddy Ruxpin bear instead of Ted as a kid that Christmas morning. They get in a dramatic fist fight, which ends with them making up and deciding to crash the Norah Jones concert at the Hatch Shell where Rex took Lori.
It turns out that Norah is one of Ted's friends, so she agrees to let John sing onstage dedicated to Lori, with the Octopussy theme song, All Time High, by Rita Coolidge and off-key. John is fiercely booed off the stage by the angry spectators, but Lori is touched by the gesture and ends her date with Rex prematurely. The next day at Lori's apartment, Ted tells Lori that John is lost without her and offers to leave forever if it would help them be together and he tells her what happened that night at Rex's. Lori then leaves to meet with John, before Ted is kidnapped by a creepy man named Donny (Giovanni Ribisi) and his obnoxious overweight son, Robert (Aedin Mincks), who had offered to buy Ted from John in an earlier scene. At their home, Ted discovers pictures of himself all over the wall, and Donny explains that when he was a little boy, he saw Ted on TV and asked his father if he could have a magical teddy bear like Ted. His father said no, and Donny vowed that he would never say no to his future son.
During Robert's play-time, Ted tricks him into playing a game of hide and seek, using the distraction to call John who is now talking with Lori about their future together, but Donny catches Ted using the phone. Donny and Robert try to flee the house with Ted before being chased by John and Lori who shows up just in time to catch them in a car chase that leads them to Fenway Park, where John punches Robert in the face, knocking him unconscious. As Donny chases Ted and climbs up one of the wall's light towers at the Green Monster, Donny grabs Ted by the foot and accidentally tears him in half, causing him to fall limp to the field below. Donny runs away as the police show up, while John and Lori at the field, run on the field beside Ted, who in his last breath tells John not to lose Lori again because she is the most important part of his life. Ted then dies, as his magic fades.
Unwilling to lose him, John and Lori rush back to Lori's apartment to try to stitch Ted back together. Though they manage to do so, they are unable to bring him back to life, so they have no choice but to accept that he is gone. Lori then brings two cups of hot chocolate, and they hear thunder crash loudly outside, but John is too upset to be scared of the thunderstorm. That night as John is asleep, Lori sees a shooting star and closes her eyes, appearing to make a wish. The next morning John wakes up and discovers that Ted has come back to life, without any visible trace of the injuries he had suffered the previous night. Lori admits that it was her wish that was responsible for saving Ted, and John finally proposes to her.
John and Lori are then married where Sam Jones (who is apparently an ordained minister) presides over the wedding service and Ted is the best man there. They then end the day by doing the "Flash Jump".