An unhappily married couple break up in this complex, painful, fascinating Iranian drama by writer-director Asghar Farhadi, with explosive results that expose a network of personal and social faultlines. A Separation is a portrait of a fractured relationship and an examination of theocracy, domestic rule and the politics of sex and class – and it reveals a terrible, pervasive sadness that seems to well up through the asphalt and the brickwork. In its depiction of national alienation in Iran, it's comparable to the work of Jafar Panahi and Mohammad Rasoulof. But there is a distinct western strand. The film shows a middle-class household under siege from an angry outsider; there are semi-unsolved mysteries, angry confrontations and family burdens: an ageing parent and two children from warring camps appearing to make friends. All these things surely show the influence of Michael Haneke's 2005 film Hidden. Farhadi, like Haneke, takes a scalpel to his bourgeois homeland.

These are modern people with modern problems. After 14 years of marriage, Simin (Leila Hatami) and Nader (Peyman Moaadi) want to split. They live in a flat with their intelligent, sensitive 11-year-old daughter Termeh (Sarina Farhadi), and with Nader's elderly father (Ali-Asghar Shahbazi), who suffers from Alzheimer's and is in need of constant care.

Both of them work, and, ambitious for their daughter's education, they have hired a teacher from her school to come to this crowded flat to give her extra coaching for her imminent and crucial exams. But now Simin wants to leave Iran for a country where there are more opportunities for women generally and for her daughter in particular; Nader says it is out of the question. They must stay in Iran to look after his father.

This debate has escalated into a demand for divorce. The very first scene shows the pair petitioning the equivalent of a magistrate for permission to proceed. This figure is not shown; the couple look directly into the camera and make their case, as it were, to us, the audience. In courtroom terms, this is something like an opening address to the jury, and the audience is invited not to decide who is right and who is wrong, but to see afresh that in such cases there is no right and wrong. Both have some justice on their side.

As the movie progresses, terrible things happen in a succession of unintended consequences. Flawed people behave badly and they will make ferocious appeals to justice and to law in preliminary hearings very similar to the divorce court, heard by harassed, careworn officials oppressed by the knowledge that there is no black and white, but numberless shades of grey. Despite the angry denunciations flying back and forth and the fizzing sense of grievance being nursed on both sides, the messy, difficult truth is that both parties can be justified, that all-or-nothing judicial war will bring destruction, and that some sort of face-saving compromise will somehow have to be patched up. The women see this, but not the men.

When Simin and Nader part, and Simin leaves to live with her mother, an instant question presents itself – with no wife in the picture, who is to do the woman's work? Which is to say, who is to do the drab, menial work of cleaning the flat, and looking after Nader's poor, incapable father? Nader already has a modern wife who has a professional career and wants to go her own way. Now he needs a traditional wife, in all but name – a drudge. So through Simin's connections, they engage Razieh (Sareh Bayat), a woman with one small daughter, whom she will have to bring to work every day, and who also has a secret she is keeping from her prospective employer. Despite the tough work involved – a 90-minute commute and the necessity of looking after a confused and incontinent old man with no special training – Nader quibbles with her about pay and this humiliating exchange is to involve Nader in the lives of both Razieh and her own prickly husband Hodjat (Shahab Hosseini). The stage is set for a terrible confrontation.

Class matters, as much as gender. One scene shows a group of people at the flat, relaxing and having fun, playing table football. Friends can join in, as well as family. But not Razieh. She is shown rather miserably getting on with something in the kitchen. When Termeh's teacher Miss Ghahraii (Merila Zare'i) comes round, she is treated as an honoured guest. She is, after all, teaching their daughter. But how about Razieh? She has an important family responsibility, too, looking after Nader's father. But she gets no respect. And she is further oppressed by her own religious sense.

When she realises that she will have to handle the old man's naked body in the bathroom, Razieh has to telephone her imam to get confirmation that this would not be a sin. She knows that in this world, the man's word is law, but which man? Her well-off employer or her impecunious husband? Everywhere in this unhappy household, there is conflict.

Farhadi shows how this situation is like a pool of petrol into which any event lands like a lighted match. Everyone is aware of their rights and how angry they feel at injustices and slights, and the women are grimly aware of the double responsibility of finding a working solution and persuading their menfolk to accept it. Yet one thing cannot be bargained away: the children. In the end, Termeh is the central figure. She sees everything, she forces her father to make a key admission, and then, excruciatingly, is put into a false position on his behalf. Her pain and anger are all mostly hidden. But she is the person on whom a terrible, unspeakable burden is to fall – a burden both judicial and moral. The adults' pettiness and selfishness have forced this on her: it is an insidious kind of abuse. With great power and subtlety, Farhadi transforms this ugly quarrel into a contemporary tragedy.

Winner of the Golden Bear at this year's Berlin film festival, Asghar Farhadi's drama focuses on the events that unfold when a recently-separated man hires a housekeeper to care for his elderly father. It's out in the UK on Friday