LONDON — In December 2010, Adam Kay was working on a British maternity ward helping a more junior doctor to perform a Caesarean section. Kay had successfully delivered well over 1,200 babies, but this operation was a disaster.

The mother had an undiagnosed condition affecting the placenta, and she should not have been allowed to go into labor. The doctors only just managed to save her life but they couldn't save the baby.

"You want healthy mum plus healthy baby, and it was the first time I'd had neither of those things and was the most senior person in the room," Kay said in a recent interview. He said that he had felt traumatized but that the reaction from the hospital "was like I'd sprained my ankle or something."

After that incident, Kay left medicine. A scene revisiting the operation does not appear in "This Is Going to Hurt," a medical drama written by Kay and starring Ben Whishaw and Ambika Mod that is streaming on AMC Plus and Sundance Now. But plenty of other episodes from his six years of working in hospitals do, in fictionalized form.

Given that the show tries to show the reality of life in a maternity ward, some moments are harrowing. But many are also funny, including a moment when Whishaw's character, an overstressed and underpaid doctor called Adam, has to retrieve, from inside a woman, a toy egg containing an engagement ring — the woman had inserted it as a surprise for her boyfriend.

The show was commissioned shortly after Kay published a collection of diaries (called "This Is Going to Hurt: Secret Diaries of a Junior Doctor") in 2017 documenting his life in British hospitals.

Kay described the book as a "confidence trick," where silly anecdotes were used to sell a book that contained serious comments about health care and about how politicians treat doctors and nurses (it was published the year after doctors in England went on strike over working conditions).

Whishaw and Mod said in interviews that the series was a joy to make. In an e-mail, Whishaw said that when he got the script, it immediately "rang out with a truth." The dark comedy "was exactly the type of humor people use when faced with awful things," he added, "and I liked the awkward, flawed, troubled person at the center of it."

Mod, in her first major role, said that the two actors received a "crash course" in obstetrics and gynecology before filming, including learning how to deliver babies with forceps and how to perform Caesarean sections. On the set, real doctors, scrub nurses and anesthetists appeared as extras, she added, while prosthetics helped give the show its realism.

"This Is Going to Hurt" was written as a one-off series, and Kay said that he had no plans to do a follow-up. He knew he would hit his "shelf life as a writer" at some point, he said, and when that happened, he expected to return to medicine, to teach or to try and change health policy.

"I've got a lot of guilt about leaving," Kay said. "Obviously, I believe the arts have enormous value, but you'd have to have quite some ego as a writer to think it was anything other than 10 steps away from saving someone's life in an operation."