Booksmart opens with two brainy high school seniors confronting a startling and humbling fact: While they hyper-focused on academics to get into fancy schools, other classmates got into the same schools, and did 10 times as much partying.

And no, the other kids didn’t take the Lori Loughlin SAT bypass. They were just better at balancing the social aspects of high school with their studies, and are about to leave with diplomas, early admission slots, and a wide circle of loving friends.

This sticks in the craw of class president/valedictorian Molly (Lady Bird’s Beanie Feldstein), who realizes that she’s been outmaneuvered, out-credentialed, and ouch — outsmarted. So she and best friend Amy (Kaitlyn Dever) do some quick, back-of-the-envelope envy algebra, and conclude the only logical thing to do, the night before graduation, is crash a notorious house party and do all the things they didn’t do the previous four years in high school.

The sets the stage for a classically structured one-crazy-night coming-of-age comedy — two party-impaired apple polishers on a quest to check the box of debauchery, leading to episodic misadventures that double as a lovely portrait of adolescent friendship, expertly acted by Feldstein and Dever.

The rapport between the two young women is exceptional, and apparent immediately — they aren’t sure where the party is, and having never been to an illicit rager, they’re also not sure how to dress. Their most important accessory: self-confidence. There is a delightful scene of the two complimenting each other’s outfits with a kind of escalating, outrageous flattery. It establishes how smart they are, how much they care about each other, and it does all of this in a completely disarming, winning way — which is the approach the movie takes to just about everything.

This includes Amy’s sexuality — she’s been out of the closet for two years, but hasn’t had a date. She has a crush on the school’s resident tomboy skateboarder (Victoria Ruesga), and urged on my Molly, plans to do something about it at the party, if they can ever find it.

The movie is directed by actress Olivia Wilde, making her first feature and a series of shrewd choices. For instance, the way she weights Amy’s sexual identity as matter of fact, presenting her as a timelessly archetypal teen caught up in the missed signals of attraction.

Wilde is equally shrewd in the way she chooses to frame Molly and Amy. The two are ferociously smart and flagrantly accomplished, and it’s OK to laugh at that — a few short scenes of their principal (Wilde’s husband Jason Sudeikis) shows how exhausted he is by their perfectionism.

Wilde, an almost-star who’s done plenty of supporting work, is also adept at carving out room for supporting players, and the movie’s picaresque structure gives her plenty of room to do it. There is a detour through a hapless yacht party thrown by a lonely rich kid (Skyler Gisondo), where they encounter a tipsy flake (Carrie Fisher’s daughter Billie Lourd) who gets drunks and jumps over the side in possible Cameron Crowe homage. Either character would be marginalized in a lesser movie, but here are given generous (and inventive) character arcs that reveal and typify the movie’s generous spirit. Ditto cameos for Will Forte and Lisa Kudrow as Amy’s affirmation-plagued parents.

Booksmart, it should be said, is a well-earned R — its dialogue is rife with the performative language of transgressive teens, and sexually candid, and you should know that your associations with panda bear plush toys will be forever altered.

But the movie clicks, and given the sorry state of movie comedy, its ability to be consistently funny stands out. It is expertly, briskly paced — shout out to the judicious and effective editing of Jamie Gross.

You would be tempted to say that Booksmart is unique, except that its part of a pattern. Coming-of-age stories about young women, written and directed by women, about to head off to college have been recent high points for comedy — Wilde’s Booksmart, Greta Gerwig’s Lady Bird, Kay Cannon’s Blockers.

Booksmart carves its own space by bringing forward the close friendship between two young women, capturing the particular power of adolescent friendship, and offering just a hint of melancholy at its special intensity and inevitable impermanence.

Booksmart. Directed by Olivia Wilde. With Beanie Feldstein, Kaitlyn Dever, Billie Lourd, Skyler Gisondo, Lisa Kudrow, Jason Sudeikis and Will Forte. Distributed by United Artists.

Running time: 1 hour, 45 mins.

Parents’ guide: R (language, drug use, sex)

Playing at: Area theaters.