For eight seasons, fans of “The Office” knew her as Kelly Kapoor, a baby-voiced customer-service rep hopelessly fixated on boys, dating and celebrity gossip.

It wasn’t a substantial role, but she stole scenes and got big laughs.

Now, Mindy Kaling gets her shot at stardom as the headliner, creator and writer of her own sitcom, Fox’s “The Mindy Project” (premieres 9:30 p.m. Tuesday), one of the fall’s buzziest new shows. And she comes close to hitting it out of the ballpark.

Kaling’s new character is Mindy Lahiri, a smart, loquacious New York City OB/GYN who pretty much rocks the workplace, but is a total mess when it comes to dating and relationships.

Seems that the problem can be pegged to a lifelong obsession with romantic comedies — Tom Hanks was her “first boyfriend” — and the frustration that comes when big-screen fantasy doesn’t sync up with real-life practicality.

In her 30s, Mindy thought she had found her Prince Charming, fittingly enough, in a movielike setting: a stalled elevator.

But sadly, he ditched her for a younger woman, and one horrible, drunken wedding toast later, Mindy had a humiliating run-in with the cops.

It’s a major wake-up call for our heroine, who figures it’s finally time to pull herself together and stop thinking that life follows a happily-ever-after path.

But that’s going to be tough to pull off, given that she’s prone to bad party-girl habits and impulsive hookups with Jeremy (Ed Weeks), a sexy and vain British doc at her practice.

Still, she’s determined to launch a self-improvement mission, starting with a little pep talk.

“I went to a good college,” she says. “I am a doctor. ... My body mass index is not great, but I’m not like Precious or anything.”

If it sounds like Fox is counting on Kaling to be its next “new girl,” you’ve got the general idea.

Like Zooey Deschanel, she oozes a quirky kind of charm that makes you want to root for her.