ATLANTA — Ja Rule, who recently spent nearly two years behind bars for illegal gun possession, landed a role in a new movie because screenwriter Galley Molina empathized with the rapper’s missteps.

“People used to ask, ‘Well, you know he’s a felon?’ And I would say, ‘Well, so am I,’ ” recalled Molina, a 44-year-old pastor who was locked up for five years for drug trafficking.

“I know his heart. I know what type of dude he is and he was probably one of the most professional guys on the set.”

“I’m in Love With a Church Girl” will debut Oct. 18 in more than 500 theaters in the U.S. Ja Rule stars as a high-level drug dealer who struggles to leave his illegal lifestyle behind after getting into a serious relationship with a church-going woman played by Adrienne Bailon of Cheetah Girls and 3LW fame.

Stephen Baldwin, Vincent Pastore and Michael Madsen also appear in the movie.

The film was produced by Molina and Grammy-winning Christian singer Israel Houghton and is based on Molina’s life. Ja Rule was hired while his gun possession cases were pending. He was released from house arrest in July after he had served most of a two-year sentence in a New York state prison before his subsequent transfer into federal custody in a tax evasion case. He admitted to failing to pay taxes on more than $3 million earned between 2004 and 2006.

“This role was very different for me,” said Ja Rule, whose film credits include “The Fast and the Furious.” “I played thug characters, but with this character, even though I play a thug somewhat, he’s really a guy going through a transition.”

The 37-year-old Ja Rule, born Jeffrey Atkins, said he put on 30 pounds in jail and read a number of books. He also earned his GED and said ex-New York State Comptroller Alan Hevesi and ex-Tyco International CEO Dennis Kozlowski urged him to pursue higher education.

“It’s really minimum — all of the fame, the movies and the music. When you’re behind that wall, all that becomes very minimum,” said Ja Rule, who burst on the music scene in 1999 and released back-to-back multiplatinum and platinum albums.