CHICAGO — For a series that has sold 5 million copies and is poised to become a major motion picture franchise, Veronica Roth’s “Divergent” had humble beginnings.

“I wrote the first one in my jammies in my parents’ house as a senior in college,” said Roth, 25. “I didn’t really know if it would go anywhere, but I thought it was worth a shot.”

The third and final book, “Allegiant,” which came out recently, ended the dystopian series that follows heroine Tris through a walled-off Chicago where 16-year-olds must be tested and choose between joining one of society’s five factions.

The Hollywood version of “Divergent,” starring Kate Winslet and Shailene Woodley, will be released in March.

After the first book sold, Roth said the publisher told her they were interested in the larger series.

“I was like, ‘Great! I have one for you and I have ideas,’ ” she said during an interview. She submitted outlines for what would become “Insurgent,” the second book, and “Allegiant.”

She promises fans a clear resolution for Tris in “Allegiant.”

Roth offered some context, saying fans should be prepared to delve into Tris’ consciousness. “It’s a little bit of a different kind of book than the first two,. It’s a little less action-heavy, a little more cerebral in Tris’ mind.”

Roth wrote the third book at her apartment on Chicago’s North Side and in a nearby coffee shop. She attended Northwestern University, where she studied creative writing with teacher Brian Bouldrey. He said Roth’s honors project was a story about a girl searching for her father at a Christian heavy metal concert.

Roth quickly showed herself to be a writer who understood plot and managing multiple characters to keep readers involved in a story.

“Veronica is an example of somebody who, really, all she needed was somebody to bounce this stuff off of and permission to take risks,” Bouldrey said.

He credits Roth for being part of the dystopian fiction trend that includes series like “The Hunger Games.”

Roth said dystopian stories are attractive because they reach in two different directions.

“You’re interested in the forward rest of the narrative, but you’re also interested in the backstory,” Roth said. “How did the world get to be this way?”

And it’s no accident that the main character in her book is a heroine, like Katniss in “The Hunger Games.”

Roth said she started writing the book from the perspective of Four, the main male character, but it wasn’t as compelling.

“When I started writing it from (Tris’) perspective, it was so much more surprising and so much more interesting,” she said. “As I wrote the series, all of the prominent and most interesting characters I created, with the exception of Four, were women.”

Roth loves that boys aren’t afraid to read stories with lead characters who are girls. But she said she thinks teens are attracted to dystopian books because of the relevance the characters have in those worlds.

“The characters in these dystopian books tend to have a lot of agency and even though they’re young have an extraordinary, sometimes unbelievable, amount of control and influence in the worlds that they live in, which I think is a powerful thing for a teenager to read,” Roth said. “It’s a difficult time.”