Panahi's last spell in prison, from which he was freed in 2023, was for protesting against the detention of two fellow film-makers who had been critical of the authorities.
His trip to Cannes was his first appearance at an international festival in 15 years, after being subject to a long travel ban.
It Was Just an Accident was shot in secret and based partly on Panahi's own experiences in prison.
"Before going to jail and before getting to know the people that I met there - and hearing their stories, their backgrounds - the issues I dealt with in my films were totally different," the director told the Hollywood Reporter.
"It's really in this context (...) with this new commitment that I had felt in prison, that I had the idea, the inspiration for this story."