Eight years ago the appearance of Cristi Puiu's The Death of Mr Lazarescu, a stoical, grimly funny story about the ghastly legacy of the Ceausescu regime, won a major prize at Cannes. It was soon followed by Cristian Mungiu's 4 Months, 3 Weeks & 2 Days, which won the Palme d'Or at Cannes and seemed to confirm that something remarkable was happening in the Romanian cinema. Now, after a longish wait, Mungiu has made another feature, Beyond the Hills, a painful and exacting picture that confirms his position as a film-maker of the first rank.

4 Months, 3 Weeks & 2 Days was set during a single wintry afternoon and evening in 1987 during the rule of Ceausescu and centres around two female students sharing a room in a bleak university dormitory. One is blond, honest, self-sacrificing, the other dark-haired, manipulative, passive-aggressive and self-centred, and the story concerns the blonde seeing the brunette through an expensive, dangerous, illegal late abortion. For the most part the film was shot in long takes with hand-held tracking shots or with static cameras, using available light.

Beyond the Hills is stylistically similar and has a parallel plot, but it's set in the present century. Ceausescu is long gone, the euro has come, but life is just as dreary and exploitative. It brought Mungiu a prize for best screenplay at Cannes, where the best actress award was rightly shared by his leading players. The two central characters are the demanding, egotistical Alina (Cristina Flutur) and Voichita (Cosmina Stratan), a thoughtful, generous novice nun. In a characteristically striking opening shot, Voichita fights her way through a crowd of male passengers at a railway station. She's on her way to welcome Alina, who has returned to Romania from Germany. They embrace in a manner that suggests an old friendship, but Alina holds on too long for Voichita, and we infer that, for her at least, something about their relationship has changed.

They travel to a smaller town and then, in another complicated long shot, they make their way up a steep country road under an overcast winter sky. At the top of the hill is an austere, jerry-built orthodox monastery that consists of a simple church and a single storey row of cells housing seven or eight nuns and a priest known simply as Father. There is no electricity or running water, just oil lamps and a well, something Alina finds repellent but Voichita happily embraces, as she does the other shortages – of food, firewood and gas.

It transpires that the two women, now in their mid-20s, were room-mates in an orphanage and had a lesbian relationship. Alina is here to take her friend back to share a liberating life waitressing on a tourist boat in Germany. But Voichita has found God in the monastery under the aegis of the stern, demanding Father and the rather more kindly Mother Superior. The Father is a harsh figure, bearded, heavily lined and appearing decades older than his 32 years. He apparently found his vocation after an epiphanic encounter with an angel at the factory where he worked but shares little of his inner life with the nuns who both fear and worship him.

The Father has a fanatical hatred of the west as a place of irredeemable corruption and opposes the pleas of Voichita and the compassionate Mother Superior to let Alina remain on his sacred premises. This is not one of those Hollywood movies about happy nuns with fulfilled vocations. In the European tradition of Black Narcissus, The Devils and Mother Joan of the Angels, it's a place of suspicion, guilt and repression, a fanatical institution not far removed from the vindictive communism it has replaced as an answer to the world's problems.

Persuasively, and in convincing detail, a steadily escalating conflict grows between the Father and the recalcitrant Alina. It threatens the stability of the monastery and then spreads out to involve the nearby town. The run-down local hospital is involved, along with Alina's former foster family and the police. Lurking outside officialdom are hints of exploitation and abuse in the form of sexual predators and traffickers who are preying on orphans and vulnerable teenagers with the community's tacit consent. On the face of it, the battle is over Voichita and Alina's attempt to make her quit Romania. But beyond this, and much deeper and less personal, is a challenge to a rigid, unreasonable and unreasoning authority. Alina is physically ill, probably suffering from tuberculosis, and mentally troubled, possibly schizophrenic. In the climactic scene she becomes the object of a brutal exorcism that is at once horrific and farcical. But in accepting her position as outsider, outcast and, ultimately, martyr, she exposes the hypocrisy, petty cruelty, indifference and lack of charity in a whole society.

Extremely long and harrowing, Beyond the Hills has been accused of being deliberately slow. But I found it riveting to watch and fascinating to think about afterwards. It's morally adroit in the way that the difficult, contrarian, ungrateful Alina is turned into a sympathetic character after first appearing to be merely an unbalanced troublemaker. The film ends on an ambiguous image, devastating in its simplicity. A battered police van, its confused passengers brought to the city as witnesses to inexplicable events, has stopped in a potholed street. The driver has just heard that the public prosecutor they're going to see is tied up with the case of a young man who's murdered his mother and published photographs of his crime on the local social network. A passing vehicle splashes filthy slush on the van's windscreen, which the wipers are attempting to clear as the film fades to black.