The depressing run of raunchy R-rated comedies pouring out of Hollywood is happily broken by this smart PG-13 one. Sexy without being smutty and funny without grossing us out, “Crazy, Stupid, Love” may rely overmuch on coincidences—especially an enormous one in the last act. But in its level of sophistication and cleverness it recalls the films of James L. Brooks—or more properly the ones from the 1980s, when Brooks was making good pictures. It’s “adult” in the best sense.

The linchpin of the script is Cal Weaver (Steve Carell), a rather drab but pleasant executive who’s shocked when Emily (Julianne Moore), his wife of a quarter-century, suddenly announces that she wants a divorce. Numb and bewildered, Cal leaves home for a dreary apartment while the fifteen-year old family babysitter Jessica (Analeigh Tipton) nurses a crush on him. Meanwhile his thirteen-year old son Robbie (Jonah Bobo) nurses an equally strong crush on her.

When Cal begins spending an inordinate amount of time sulking at a local club, he’s noticed by Jacob Palmer (Ryan Gosling), a womanizing stud with a chain of snappy come-on lines. Taking pity on the schlub, Jacob remakes Cal, instructing him on his wardrobe and haircut and teaching him how to pick up women, the first conquest being a desperate—and enthusiastic—lady (Marisa Tomei). But that success leads to a string of one-night stands, wittily recorded in a virtuoso tracking shot that follows his process from table to table over time.

But of course Cal’s still pining over Emily, and her dalliance with a haplessly smitten co-worker (Kevin Bacon) proves considerably less satisfying than either of them had hoped. Meanwhile the babysitter decides to declare her interest in Cal in a fashion that boomerangs when her parents find out, and Robbie’s efforts to woo her escalate. There’s a major development, however, when Jacob finds true love in Hannah (Emma Stone), a young lawyer who’s rejected his advances in the past but succumbs after herself being romantically disappointed by her clueless boss, and asks Cal for advice about how to win over her parents.

Everything comes to a head as Robbie’s middle-school graduation approaches, with twists involving Stone, Tipton and Tomei setting off particular sparks. But rest assured all the characters end up properly coupled.

While that conclusion follows established formula, however, getting there affords a great deal of enjoyment—and a bit of poignancy as well. Dan Fogelman’s script is filled with amusing lines and bits of business (using Miyagi as a verb is an inspired moment, and the initial encounter between Jacob and Hannah in his plush home refers cleverly to another popular film, this time “Dirty Dancing”). It even comments wryly when it uses a cliché of the genre. And though it often touches on sexual matters, for the most part it does so obliquely, and directors Glenn Ficarra and John Requa are equally discreet in handling matters that in other hands could easily have turned coarse.

Carell anchors the film with a turn that amply demonstrates his comedic skill, but also gives him moments of sad-sack drama as well, while a buffed-up Gosling handles the part of his slick but vulnerable mentor with aplomb. On the distaff side Moore brings dramatic heft to the part of Cal’s conflicted wife, and Stone is engagingly over-the-top as the ambitious but needy Hannah. The younger players—Tipton and Bobo—avoid preciousness, while Bacon gives Emily’s office suitor almost more shading than the role can bear. And Tomei is positively ferocious as a woman scorned. No problems on the technical side, with Andrew Dunn’s cinematography lending the images a nice sheen and the music (by Christophe Beck and Nick Urata) avoiding the obtrusiveness so common in scores for Hollywood comedies.

“Crazy, Stupid, Love” requires you to swallow a few unlikely twists in the last act, but that’s the nature of domestic farce. And it’s so adroitly put together and engagingly acted that they go down easily.