IFC Films has scooped up the U.S. rights to Trevor Nunn’s period spy thriller “Red Joan” with Judi Dench and Sophie Cookson, which had its world premiere at the Toronto Film Festival on Thursday.

Represented in international markets by Embankment Films, “Red Joan” explores the complex persona and legacy of Joan Stanley, a seemingly demure physicist who was also a long-serving British spy for the KGB. “Red Joan” was written by Lindsay Shapero (“Royal Wives at War”) based on Jennie Rooney’s best-selling novel of the same name.

“Red Joan” stars Dench as Joan Stanley, a retired scientist living in a London suburb who gets arrested by MI5 and accused of providing intelligence to Communist Russia. We flash back to 1938, and young Joan (Cookson) is a new physics student at Cambridge, where she is drawn into a circle of pro-USSR politicized youths and falls for a young communist, Leo Galich. When the World War II begins, Joan goes to work for a top-secret British intelligence project and soon faces an impossible dilemma, having to choose between betraying her country and loved ones or saving them.

Oscar-winning producer David Parfitt (“Shakespeare in Love”) produced for Trademark Films, while Ivan Mactaggart (“My Week with Marilyn”) of Cambridge Picture Company and Alice Dawson (“The Party”) co-produced.

IFC Films is planning to release the film theatrically in 2019.

“It’s very exciting to have IFC steer our film through to release across the U.S. and we look forward to working with this great team. The public reaction to the film here in Toronto has been great to see — not only does Judi give an exceptional performance, it’s clear that Sophie Cookson, in the role of the younger Joan, commands our attention and is a bright young star, with a great future,” Nunn and Parfitt said.

Jonathan Sehring and Lisa Schwartz, co-presidents of IFC Films, said they “were struck by the deep moral dilemma presented by ‘Red Joan,’ but also by the romanticism unleashed by a true tale of espionage and a strong female anti-heroine.”

“The film is full of a subtle complexity and slow-burn suspense that we hope will capture audiences across the country,” said the executive pair, who also praised Dench and Cookson for their “top performances.”

The deal for the film was negotiated by Arianna Bocco, exec VP of acquisitions and production at IFC Films, and Embankment Films on behalf of the filmmaker.

Nunn previously directed the original London production of “Les Misérables” and Helena Bonham Carter’s “Twelfth Night or What You Will.”

Following Toronto, “Red Joan” will play at the San Sebastian and Zurich film festivals, where Dench will be honored with special awards. The movie will be released by Lionsgate in the U.K.

IFC Films’ recent acquisitions also includes “Charlie Says,” the Manson family drama directed by Mary Harron (“American Psycho”), which world premiered at Venice. IFC Films’ upcoming releases include Paul Dano’s “Wildlife” and Ethan Hawke’s “Blaze.”