"One does not imprison Voltaire," General de Gaulle is reported to have said, in response to a suggestion that Jean-Paul Sartre could be silenced with a jail sentence. If only the Iranian government showed that kind of class. In December 2010, the film-makers and pro-democracy activists Jafar Panahi and Mohammad Rasoulof were sentenced to six years in prison for alleged crimes against national security. Grotesquely, Jafar Panahi – the director of The White Balloon, Crimson Gold and Offside – was also subject to a 20-year ban on film-making, and forbidden moreover to give interviews or leave the country in that period. With this crass, quasi-Soviet attempt to crush his creativity and humanity, the government disgraced itself in a unique fashion. Hollywood big-hitters have signed petitions, but in the current climate, pressure from the US could just be counterproductive.

Meanwhile, Panahi and Rasoulof have become cinema's prisoners of conscience, and while pursuing his appeal, and confined to his apartment under effective house arrest, Panahi managed to make this gripping, zero-budget film about a day in his life, shot entirely within his flat, partly on a simple DV camera and on his iPhone. He then had it smuggled it out of the country on a USB stick, reportedly hidden in a cake – and it was shown at the 2011 Cannes film festival. (Rasoulof had a feature film at Cannes, too, the devastatingly sombre Goodbye, made under conditions almost as constricted as Panahi's.)

This Is Not a Film is a compelling personal document, a quietly passionate statement of artistic intent, and an uncompromising testament to his belief in cinema. The government is trying to cut off the oxygen to his livelihood and life. But this film-maker is hitting back.

Panahi's title hints at the Magrittean absurdity of what he has to do to get round the law. Technically, it is the work of its cameraman Mojtaba Mirtahmasb, and Panahi is not being "interviewed" but rather speaking lines, like an actor, on the subject of film-making. The result is a heartbreaking, agonising study of loneliness. Panahi just hangs around the flat, eating, watching the news, surfing the net on his Mac and iPhone, taking depressing and inconclusive calls from his lawyer. He tries and fails to look after a neighbour's querulous pet dog, which he has to return to its owner because it is upsetting his pet iguana, Igi. His wry sense of humour is impressive, and his elegant dignity is profoundly moving.

The neighbours are all preparing for New Year's Eve parties, and Panahi speaks about his family members making various festive outings. (They do not appear on camera.) But there are no outings for Panahi. He stays put and what he mostly does is talk – he talks to Mirtahmasb about his work, with a fluency and intensity born of a sense that everything is now at stake.

Impulsively, Panahi acts out an unproduced screenplay, on the theme of incarceration, marking approximate set outlines with tape on the floor, but then almost breaks down with anguish and frustration. This is not what cinema is – and here the title changes from surreal joke to tragic truth. Using DVD clips from his films Crimson Gold and The Circle, Panahi shows us that the best, most serendipitous moments were improvised, taking their cue from the real world. (This has to be the most heartwrenching "director's commentary" imaginable.) Panahi did not know what his actors were going to do, but he shaped and guided their instincts, both on location and in the editing suite. You can't script this: you need freedom. And freedom is precisely what Panahi doesn't have.

Finally, he is shown befriending a college student who is making some extra money with a job collecting the garbage from the apartments in Panahi's building. Panahi grabs his camera and follows him, desperate for someone to talk to, excitedly interviewing this somewhat baffled young man about his life. He follows him to the apartment complex gates, beyond which the parties and fireworks are in full swing. He can go no further. You can feel the prison door clang shut in his face. This film is a samizdat cine-poem in defence of cinema and freedom: the only response is contempt for those government bullies and bureaucrats ranged against Jafar Panahi.