On entering her 10th decade last year, PD James – legend of crime writing and creator of Adam Dalgliesh, one of Britain's best-loved fictional sleuths – decided that the time had come to have some fun. Disinclined, at 90, to begin another Dalgliesh novel, on the grounds that to die leaving a manuscript unfinished would be "intolerable", she chose instead to pursue a long-cherished, if surprising, ambition.

"I had it at the back of my mind for quite a time," she says. "And after I finished The Private Patient [her final Dalgliesh novel] I saw I had the opportunity to indulge myself. I wanted to combine my two enthusiasms: writing detective fiction and reading Jane Austen. I thought it would be enjoyable to revisit the characters in Pride and Prejudice and to create a really original, exciting, credible detective story at the same time. It was great fun to write it, it really was."

The result is Death Comes to Pemberley, published this week. True to the original in tone and tempo, but with a nice, messy murder offering a window on to both the inner lives of the familiar characters and the legal and medical systems of the time, the book stands as an estimable sequel to Austen's text. Set six years after the conclusion of Pride and Prejudice, the novel finds Elizabeth and Darcy happily ensconced at Pemberley: tending to the estate and its tenants, delighting in their two young sons, deeply in love. Jane and Bingley live just 30 miles away, Mrs Bennet remains at a conveniently inconvenient distance, and all is highly felicitous – until the night when a carriage careens out of the wind-lashed darkness and disgorges Elizabeth's wayward sister, Lydia, screaming that her husband, the nefarious Wickham, is dead. The result is a murder trial in which the Darcys find themselves inextricably entangled and which threatens their present happiness and future security.

The house that gives its name to the novel stands at its physical and emotional heart. The gifts it bestows on its inhabitants – both owners and servants – and the duties and loyalties it exacts from them exert a directional pull on the course of the book. It is also the archetypal setting for a murder mystery, and no one understands why better than James herself. "The country house was very much the setting of the orthodox Christie crime novel," she says. "It looms large in the imagination as a place of fundamental goodness and propriety, order and peace; to have the incredible eruption of murder into that comfort, blowing it apart, is shocking. It is that contrast which makes the country house so important to crime fiction. And Pemberley is the ideal country house in every sense."

James's sensitivity to the changing role of the country house over the course of a writing career that has spanned nearly half a century goes some way to explaining why her novels amount to so much more than detective fiction by numbers. The career of her poet-policeman, Dalgliesh, begins and ends with a country house murder. In his first outing, 1962's Cover Her Face, he is dispatched to Martingale manor house in Essex to investigate the violent death of a young woman; in The Private Patient, published in 2008, he lights out for Cheverell Manor in Dorset to apply his brand of thoughtful, practical logic to a similar crime. Read the books side by side and the reverberations ring out: both victims are female; both have been throttled in their beds; both are discovered the following morning by other members of the household, triggering mirroring scenes of shock and distress. But nearly 50 years have elapsed between the two novels, and beneath the superficial similarities, the world has changed.

In Cover Her Face, the victim is an unmarried mother, charitably employed by the mistress of the manor (the house is still in family hands) as a parlourmaid, on the commendation of the warden of a refuge for "delinquent" girls. The day before her murder, after the annual church fete, her relationship with the favoured elder son is disclosed, to general outrage. Dalgliesh arrives to find a community in tumult, the horror of the murder tapping into a wider mid-20th century unease about social class.

Fast-forward 46 years, and the situation Dalgliesh is confronted with looks identical, but differs in every underlying detail. The manor house in The Private Patient has been sold by its ancestral owners to cover their debts and bought by self-made plastic surgeon George Chandler-Powell. He runs a private clinic out of one wing to finance his occupation of the building, maintaining the appearance of a well-appointed country house for the satisfaction of the patient-guests, one of whom, Rhoda Gradwyn, a successful investigative journalist, is the murder victim. The plot is still driven by status anxiety, but of a modern, more meritocratic kind: characters are exercised by their place in the world, certainly, but view that place in terms of career, not class. Motives – from the victim's and the surgeon's to that of the murderer – are fiercely individualistic, frequently financial, and fully 21st-century. Although James says she "didn't set out to provide a chronicle" of the attitudes of her time, by writing her way through the late 20th century over the course of 16 crime novels, that's precisely what she has produced.

"A detective story can give a much truer picture of the society in which it's written than a more prestigious literature," James suggests. "If we want to know what it was like – actually like – to work in an office between the wars, we should go to Murder Must Advertise. It's all there: the people and personalities; the inter-departmental rivalry; the great excitement of having a flutter on the Grand National; right down to how much things cost and attitudes to sex and class. I wanted my books to do the same; to be unambiguously set in the present day, so that they give a picture of the life we're living. And if I'm lucky enough to be read in 50 years' time, I hope people will be able to point to them and say: that's what it was like."

Phyllis Dorothy James was born in Oxford in 1920 – a year that's doubly celebrated by crime aficionados, since it also heralded the dawning of the Golden Age of detective fiction, that interwar flowering of intricately plotted mysteries, in which the preternaturally shrewd detective is invited to pick his way through a liberal scattering of clues and red herrings, before confronting reader and murderer with his irrefutable conclusions in the final pages.

The eldest of three siblings whose father worked for the Inland Revenue, James left school at 16 to work in a tax office herself, and in 1941 married Ernest White, of the Royal Army Medical Corps. He was completing his training at the Westminster Hospital, so at 21, James followed him there, took a job distributing ration books and found herself in London at the height of the blitz. She says she can't remember being frightened until the arrival of the doodlebugs in 1944: "Very scary: they flew low and were extremely loud, until suddenly the noise would stop, and you'd hear a huge explosion and think, thank God it wasn't me." During this time she gave birth to her second daughter, Jane, in hospital (her first, Claire, was born in 1942). "In the daytime, we had to put our pillows over the tops of the cots, to protect the baby in case a bomb blew the windows in. At night, our beds were moved into the corridors, away from flying glass, and the babies were taken to the basement. I remember lying there at night, very weepy, thinking if there's a bomb, how do I find my baby? That was the worst part of the war for me."

But the aftermath was to prove tougher than the war itself. James's husband returned with schizophrenia and unable to work (he died at 44), so it was left to James to provide for her young family. She moved in with her parents-in-law, studied hospital administration and, from 1949-68, served as an administrative assistant with the North West Regional Hospital Board in London. The children went to boarding school and were looked after by their grandparents in the holidays, leaving James free to work and, in the evenings, to embark on her first book.

It had always been her ambition – "in fact, my intention" – to write, and the decision to try her hand at detective fiction, following in the footsteps of her heroes Margery Allingham and Dorothy L Sayers, was straightforward. When it came to choosing a detective, however, she turned her face against the tradition for the talented amateur, from Sherlock Holmes to Sayers's Lord Peter Wimsey, and plumped for a professional instead. "From the first I was aiming at credibility. I thought, amateurs don't really have the resources to investigate a murder; I must have a professional. And I couldn't have a woman because there were no women in the detective force then. I simply produced the kind of hero I'd like to read about: courageous but not foolhardy, compassionate but not sentimental."

Cover Her Face (written, as were all her books, under her maiden name) was, she says, "very much of its time: a pregnant girl now would be given a flat of her own and enough income to bring up her baby, not forced into a mother and baby home. But it's difficult not to feel fond of the first book you write. Books are like babies: they bring their own love with them."

James continued with her day job until she retired. Her career in the health service furnished a rich vein of medical and bureaucratic knowledge that runs through her books: one of her best-known novels, Shroud for a Nightingale, is set in a nurses' training house, and explores the intense relationships that develop in closed communitiesIn 1968, however, she sat the civil service open exam and began work in the Home Office. Appropriately enough, she eventually became a senior civil servant in the crime department.

"I was quite proud of getting in," she says. "They didn't normally want people who'd left school at 16, and very few women were successful. But I was number three in the country on the exam, which absolutely amazed me." She beams. "I've still got the letter. And believe it or not, it began 'Dear sir', and they'd crossed out the 'sir' and written 'madam' over the top."

The first of her books to feature a female lead, private detective Cordelia Gray, is called An Unsuitable Job for a Woman, and one wonders to what extent James's own experiences in the workplace inspired it. Tough, smart, working-class Gray is arguably the first modern female detective in crime fiction, paving the way for the likes of Sara Paretsky's VI Warshawski and Thomas Harris's Clarice Starling. There was great excitement around the creation of the character at the time, but James gave her only one further full-length outing, in 1982's The Skull Beneath the Skin, and she has since been criticised for casting her feminist role model aside. But the decision, she says, was forced on her. "The producers of the film Mrs Brown said they'd like to make some Cordelia Gray programmes, and asked if they could develop the character. I was concentrating on Dalgliesh, and also by this point had Kate Miskin [Dalgliesh's sidekick], who's very like Cordelia – a gutsy girl from a deprived background. So I thought I'd let them try it. Then one day I was at the hairdresser's and I read that the actor playing Cordelia was pregnant, but was going to carry on with the part and make her into an unmarried mother. I got on to one of the directors, and he said, we thought she could have an American lover who's deserted her, and she'll continue to do her job while she's pregnant. And I said, Cordelia was not the sort of girl to have an affair resulting in a pregnancy. If she'd had an affair she wouldn't have had a baby; if she did have a baby, she would take the view that the father had a right to know, and the child had the right to a father. I realised my character had gone."

It was at around this time that James made her sole foray into science fiction. The Children of Men (later turned into a film by Alfonso Cuarón) is a dystopia set in 2021 in an England in which infertility is endemic, and the population is steadily declining. "I didn't think of it as science fiction at all, actually. What happened was that I read a review of a science book that dealt with the extraordinary fall in fertility of western man – we're a third as fertile as our grandparents were. And I wondered what sort of world we'd get if infertility was absolutely general and complete, so that a time came when nobody was giving birth. It's a grim book, very grim – there's chaos at the heart of it." The novel was roundly praised by critics (writing in the New York Times, Caryn James called it "a trenchant analysis of politics and power that speaks urgently to this social moment"), but for James it was a one-off rather than a springboard into a different genre. "I don't think," she says, "that we necessarily choose our genre; the genre chooses us."

What, then, does detective fiction say about her? "That I am a woman who likes life to be ordered. In a long life, I have never taken a drug or got drunk, and I say that not as a matter of pride: it's because the idea of being out of control is appalling to me. I think that when one writes detective stories one is imposing order, and a form of imperfect but human justice, on chaos." In fact, as with the later work of her hero Dorothy L Sayers, a great deal of the fascination of James's detective fiction lies in the way chaos flourishes in the midst of the novels' rigid structure – the internal psychological mess that brings about murder. "I think there's been a huge change since the novels of the Golden Age," she suggests. "What was popular then was the puzzle: such qualities as psychological truth or even atmospheric location were secondary to it. For me, characterisation is at the heart of my books. From the start, I felt that what I was doing was examining human beings under the strain of an investigation for murder. And such an investigation tears down all the walls of privacy that we build round ourselves and reveals us for who we are. It's a fascinating way of dealing with people."