Melvin Udall is a misanthropic best-selling romance novelist in New York City, whose obsessive–compulsive disorder has him avoiding stepping on sidewalk cracks while walking through the city, and eating breakfast at the same table in the same restaurant every day. He takes an interest in his waitress, Carol Connelly, the only server at the restaurant who can tolerate his uncouth behavior.
One day, Simon Bishop, a homosexual artist who is Melvin’s apartment neighbor, is assaulted and nearly killed during a robbery. Melvin is intimidated by Simon’s agent, Frank Sachs, into caring for Simon’s dog, Verdell, while Simon is hospitalized. Although he initially does not enjoy caring for the dog, Melvin becomes emotionally attached to it. He simultaneously receives more attention from Carol. When Simon is released from the hospital, Melvin is unable to cope emotionally with returning the dog. Melvin’s life is further altered when Carol decides to work closer to her home in Brooklyn so she can care for her acutely asthmatic son Spence. Unable to adjust to another waitress, Melvin arranges through his publisher (whose husband is a doctor) to pay for her son’s considerable medical expenses as long as Carol agrees to return to work. She is overwhelmed at his generosity.
Meanwhile, Simon’s assault and rehabilitation, coupled with Verdell’s preference for Melvin, causes Simon to lose his creative muse. Simon is approaching bankruptcy due to his medical bills. Frank persuades him to go to Baltimore to ask his estranged parents for money. Because Frank is too busy to take injured Simon to Baltimore himself, Melvin reluctantly agrees to do so; Frank lends Melvin the use of his Saab 900 convertible for the trip. Melvin invites Carol to accompany them on the trip to lessen the awkwardness. She reluctantly accepts the invitation, and relationships among the three develop.
Once in Baltimore, Carol persuades Melvin to take her out to have dinner. Melvin’s comments during the dinner greatly flatter—and subsequently upset—Carol, and she abruptly leaves. Upon seeing Carol, who is frustrated, Simon begins to sketch her, semi-nude, in his hotel room, which rekindles his creativity, and he once more feels a desire to paint. He briefly reconnects with his parents, but is able to tell them that he will be fine.
After returning to New York, Carol tells Melvin that she does not want him in her life anymore. She later regrets her statement and calls to apologize. The relationship between Melvin and Carol remains complicated, until Simon (whom Melvin has allowed to move in with him, as he had to sell his apartment) persuades Melvin to declare his love for her. Melvin goes to see Carol, who is hesitant, but agrees to try and establish a relationship with him. The film ends with Melvin and Carol walking together. As he opens the door at an early morning pastry shop for Carol, he realizes that he has stepped on a crack in the pavement, but does not seem to mind.