I forget how to breathe. I am being pulled underwater. The taxi driver carries me into the emergency room because I’ve passed out in the cab and my mother can’t lift a 12-year-old.

In How We Die, the American surgeon and writer Sherwin Nuland describes the physical effects of pneumonia: “The microscopic air sacs called alveoli swell and are destroyed by inflammation. As a result, proper exchange of gases is prevented, and blood oxygen diminishes while carbon dioxide may build up until vital functions can no longer be sustained. When oxygen levels drop below a critical point, the brain manifests it by further cell death.”

Someone puts a mask on my face. I taste the sweetness of the oxygen, like tasting sky.

I have a 107-degree fever. At home, my mother had put me in a bathtub with ice cubes in it. In intensive care, there are tubes or snakes in my arms; there are good or evil nurses. An intern sticks a needle into an artery to measure my oxygen levels. In the next bed over, a baby’s heart stops.

Three weeks later I leave the hospital, but I do not get completely better.

The cough is so bad it’s like an animal that lives with me and sleeps in my bed. On the worst days my mother tries to get me to stay home from school, but I am adamant about going.

I have fevers every evening, shivering through dinner, homework, bath. There is no question that this is the way I will feel forever; there is no idea of after the fever, or if there is any idea like that, it is wan, unconvincing, because the fever is a world.

I wake up with my nightgown soaked in sweat, the sheets wet with sweat. The sweat is shameful, something to be hidden; the fever is also something shameful.

Doctors are consulted, antibiotics prescribed. I go into the hospital and come out of the hospital. My father, who is a doctor himself, is very quiet when the doctors talk. There is no name for what is wrong with me.

One day when I cough, there is blood in the tissue. I taste blood in my mouth. I know this means that I am dying, and so I do the sensible thing and tell no one, not my mother, my father, my sisters, my doctor.

When I cough, there is blood in the tissue. I know this means I am dying, so I do the sensible thing and tell no one

My mother plots and pleads and calls up doctor friends to get me an appointment with a famous lung specialist. When I am finally in his office she explains that I can’t walk up a flight of stairs in our house without being out of breath. The doctor asks me how I feel. I don’t say anything about the blood I am coughing up. I say, “I feel fine.”

In the meantime, I am reading strange books. I am reading exclusively books about genocide: Primo Levi, Elie Wiesel, firsthand accounts of the Armenian genocide. I have a great, endless appetite for these books, not just for people dying but people dying in great numbers, including children, wars, massacres, naked bodies in trenches. I read them one after another. I am reading with something like desire. I want to see children die.

My mother buys me silk nightgowns for the hospital, because cotton hospital pyjamas with their gaping holes and faded prints and little ties are demoralising. The big clustering groups of doctors and residents and medical students lift up these frothy honeymoon nightgowns to listen, one after another, to my mysterious lungs. I am embarrassed to be half naked in front of a crowd of young doctors.

Facebook Twitter Pinterest Elie Wiesel, the writer and Nobel Peace prize winner. Photograph: Francois Guillot/AFP/Getty

A family of Pentecostal Christians comes to visit the diabetic child I am sharing a room with. They light candles, and start chanting in Spanish to banish the devil, and throw rice, which is surprisingly loud as it hits the floor. The nurse comes in and screams at them for lighting candles in the hospital, especially around my oxygen. They blow out the candles, and the minute the nurse leaves, they light them again. They offer to banish the devil over me, and my mother lets them.

I write a story in the school literary magazine about a girl in the hospital, which ends with a voice calling to her: “Come to me, daughter of the wind.” The voice is calling her to give in, pack it up; it’s almost cellular, this voice, something in the girl’s body telling her to stop fighting, to go under. The line brings something back to me now. How death, this thing you are resisting, fighting, terrified of, suddenly turns and becomes seductive. As Virginia Woolf writes in her dazzling meditation “On Being Ill”, “illness often takes on the disguise of love, and plays the same odd tricks”.

Eventually I have a test where they put a tube down my throat and inject white dye into my lungs. This is supposed to show the doctors whether the chronic infection is localised enough for them to operate. In the x-rays, it looks like there are snow-covered trees in my lungs.

The night before my surgery, the sound of bagpipes floats through the hospital hallways. The sound frightens me, it is so incongruous and beautiful and funereal. My mother explains that the son of a policeman has cancer, and the police have sent a troupe of bagpipe players to play for him.

The operation lasts seven hours. They remove half of one of my lungs. In the recovery room, a tube in my throat, tubes draining my lungs through small holes between my ribs, a tube in my arm, I swim up from the anaesthetic and ask for my mother. A nurse says to me, “You are too old to call for your mother.”

My older sister is in medical school. She is not intimidated by the tubes and climbs into the bed with me, which cheers me up. She brings me a red tin of madeleines that she has made. My best friend does not visit me in the hospital. She has decided to stop being friends with me.

How does it feel to come so close to death you can breathe its atmosphere? I want to come as close as I can

When I come home, I am 60 pounds. I am too weak to open a door. My hair has fallen out in the front, so I have to cut it all off. My father takes me on slow walks down our street, but I can’t yet make it around a city block.

You read about soldiers who have trouble coming back into civilian life. They can’t fit themselves back into everyday preoccupations: whether to wear a winter coat, whether to go to a party, whether to eat lunch. They are totally and completely wrapped up in the shocking time; they are constantly drawn back to it; they are in love with it the way you love someone who has hurt you: it will not let them go. In the end it doesn’t matter if they are the best or worst hours of your life; all of that is irrelevant and stripped away: you are drawn back into it. After the hospital, I feel like that, but I don’t know what to call it. I go back to The Road from Home: The Story of an Armenian Girl.

Maurice Sendak sat with the people he loved as they were dying and drew them. To some, this might seem like a perverse or weird thing to do, but I understand it completely and intuitively. In fact, I am doing something like it myself. I am writing about deaths. Not the deaths of people I loved but of writers and artists who are especially sensitive or attuned to death, who have worked through the problem of death in their art, in their letters, in their love affairs, in their dreams. I’ve picked people who are madly articulate, who have abundant and extraordinary imaginations or intellectual fierceness, who can put the confrontation with mortality into words in a way that most of us can’t or won’t. I chose writers who meant something to me, whose voices were already in my head, whose approach toward death was extreme in one direction or another: inspiring or bewildering or heroic or angry.

Facebook Twitter Pinterest Susan Sontag at the Edinburgh International Book festival in 2003. Photograph: Murdo Macleod/The Guardian

Sigmund Freud, in great pain, refused anything stronger than aspirin so he could think clearly, and finally chose the moment of his own death. Susan Sontag, on the other hand, fought her death to the end, believing on some deep irrational level she would be the one exception to mortality. Sendak worked his whole life on death, taming his fear and obsession through drawings, and finally creating out of his wild imagination a beautiful painterly dream to comfort himself. The month before he died, John Updike laid his head on his typewriter, because it was too hard to type up his final poems about dying and he was ready to give up, and then he found the strength to finish them. Dylan Thomas, in his last days, left his mistress downstairs at a party and went upstairs to sleep with the hostess, hurtling along with his peerless mixture of vitality and self-destruction; as he put it, “I sang in my chains like the sea”.

There are in these deaths glimpses of bravery, of beauty, of crushingly pointless suffering, of rampant self-destruction, of truly terrible behaviour, of creative bursts, of superb devotion, of glitteringly accurate self-knowledge, and of magnificent delusion. There are things I could never have guessed or theorised or anticipated, and it is in the specifics, the odd, surprising details, the jokes, the offhand comments, that some other greater story is told and communicated.

Why did Sendak want to draw death? Why did Annie Leibovitz take her controversial and startling last photographs of Susan Sontag as she lay dying and after she died? Why did the Victorians photograph dead babies propped up in prams and on people’s laps? Why did the Romantics make death masks? “I do it because I can’t not do it,” as Sendak said about his art generally. “Something malfunctions in me.”

I think if I can capture a death on the page, I’ll repair or heal something. I’ll feel better. It comes down to that.

Facebook Twitter Pinterest Maurice Sendak standing by a life-size scene from his book Where the Wild Things Are at the Children’s Museum of Manhattan. Photograph: James Keyser/Time & Life Pictures/Getty Image

I start with a room. Freud’s room, with its French doors overlooking the blossoming almond tree; John Updike’s institutionally homey room at the upscale hospice in Danvers, Massachusetts; Susan Sontag’s last room at Sloan Kettering; Dylan Thomas’s room at St Vincent’s, with its oxygen tent; Maurice Sendak’s sprawling “comfort care” room at Danbury hospital. I very conspicuously do not belong in these rooms.

This is one of our few powerful taboos. Nuland writes, “Modern dying takes place in the modern hospital, where it can be hidden, cleansed of its organic blight, and finally packaged for modern burial. We can now deny the power not only of death but of nature itself.” We do not see death the way people in other centuries saw it all the time – a mother in childbirth in a four-poster mahogany bed, a baby carried down the hall in a sheet, a child burning up with scarlet fever. We do not see people die in our homes very often, and death is something that we can forget about, cordon off. But the heat of curiosity is there. Sontag once wrote that “the appetite for pictures showing bodies in pain is as keen, almost, as the desire for ones that show bodies naked”. She captures a near-pornographic feel to death, a desire to see that feels illicit, wrong.

A reporter asked Leibovitz about the photographs she took of people close to her – Sontag and her father – dying and dead, and she said: “You find yourself reverting to what you know. It’s almost like a protection of some kind. You go back into yourself. You don’t really know quite what you’re doing. I didn’t really analyse it. I felt driven to do it.”

Is that drive prurient, voyeuristic? Is there something sick or unhinged or vulturish about it? Even if there is, the curiosity feels natural.

The problem with the project is that it could have gone on forever. There were so many deaths I wanted to dive into: William Blake’s happy death, where he sat up in bed and saw angels; Honoré de Balzac killing himself through work and coffee; Primo Levi’s probably suicidal fall down the stairs; Christopher Hitchens’s fierce commitment to reporting his death; Virginia Woolf’s descent into the river, with stones in her overcoat; Franz Kafka starving, like his hunger artist, in the sanatorium; Leo Tolstoy leaving his wife and dying near a train station at the stationmaster’s house; F Scott Fitzgerald’s heart attack in Hollywood. All of them seemed to call to me.

Facebook Twitter Pinterest Christopher Hitchens Photograph: Lydia Goldblatt/Guardian

I found the portraits of these deaths hugely and strangely reassuring. The beauty of the life comes spilling out. The power of an inspiring mind working on the problem. Somehow these sketches were freeing, comforting, exhilarating, in part because the people I was writing about lived great, vivid, gloriously productive lives. There is something about the compression of the final moments, the way everything comes rushing in, the intensity, that is beautiful, even though the death is not.

Sendak owned Keats’s death mask, which he kept in a wooden box. He adored it. He liked to stroke its forehead. I saw it and it was very beautiful. Why would anyone want to own a death mask? I asked myself. But I knew. In a way, I was writing death masks.

I would not have bought the New York Post with the dead baby on the cover, but since it is lying on the table at the coffee shop, I am reading the story and continuing on page four. The family had driven in from New Jersey. The father was taking a picture on the promenade outside the sea lion pool at the Central Park Zoo, and the mother was holding their six-month-old, Gianna, when a branch fell and killed the baby. When I come to the end of the story I feel like I haven’t been given enough detail, but what other detail was I looking for? What more detail could I possibly need?

Updike laid his head on his typewriter because it was too hard to type his poems. Then he found the strength to finish

I had taken my own baby to the Central Park Zoo a few weeks before. I had shown him that giant cuckoo clock with animals and their instruments, the same clock I used to see as a child, on the promenade outside the sea lion exhibit. There is an incantatory quality to reading the Post article. Am I telling myself that in a world full of rotting branches on glorious days, my own baby is safely sleeping in a green-painted crib on the bottom floor of my house? Am I trying to prove that this specific tragedy happened to this specific baby and in fact has nothing at all to do with anything that could in any way happen to my baby? As Freud put it, “Our habit is to lay stress on the fortuitous causation of the death – accident, disease, infection, advanced age; in this way we betray an effort to reduce death from a necessity to a chance event.”

There is, of course, in all of this fascination with death, with extremities, a primitive, ritualistic dividing of the well from the sick, the alive from the dead, the lucky from the unlucky. Sontag wrote about visiting the very sick in a draft for a short story: “making time to drop by the hospital every day, is a way of our trying to put ourselves more firmly and irrevocably in the situation of the well, those who aren’t sick, who aren’t going to get sick, as if what happened to him couldn’t happen to one of us.”

Facebook Twitter Pinterest John Updike in the mid 60s. Photograph: Susan Wood/Getty Images

In Rabbit at Rest, Updike’s Rabbit Angstrom has a heart attack on a sailing boat with his granddaughter: “His chest feels full, his head dizzy, his pulse rustles in his ears, the soaked space between his shoulder blades holds a jagged pain.” And: “The sense of doom hovering over him these past days has condensed into reality, as clouds condense into needed rain. There is a lightness, a lightening, that comes along with misery: vast portions of your life are shorn off, suddenly ignorable. You become simply a piece of physical luggage to be delivered into the hands of others.”

How does it feel to come so close to death you can breathe its atmosphere? I can’t get back to the year I knew, but I want to come as close as I can.

Before being diagnosed with oesophageal cancer, healthy but maybe a little worse for the wear, Hitchens wrote in his memoir: “I want to stare death in the eye.” And it is that staring that is rarely granted to us. Sontag once wrote, “One can’t look steadily at death any more than one can stare at the sun.” And Freud argues that we can’t even imagine our deaths: “It is indeed impossible to imagine our own death; and whenever we attempt to do so we can perceive that we are in fact still present as spectators.” And when people we love die, we are so steeped in loss and love and dread that we can’t see, much less stare.

It’s interesting how quickly the imagination turns death into something else; how quickly, cleverly, resourcefully we flee. “Full fathom five thy father lies … Those are pearls that were his eyes.” We can, if we work hard enough, make death into pearls. What would it be like if the line were: “Those aren’t pearls that were his eyes”?

When the terror of death blows through you, what do you do? What do you reach for? Aside from, of course, a drink or another person. In his last days, Updike kept The Book of Common Prayer next to his bed and prayed with his wife Martha and the reverend who visited him. Even Sontag, a passionate atheist, called her assistant to pray with her one morning. Not that this prayer comforted her or that she believed it for a second – even his description of her request is suffused with scepticism and irony – but, still, even she seems to have said a prayer.

To me, religion has never been consoling. I can’t get anything out of even the cadences of it. It feels like a foreign language. I sometimes find the reassurance I imagine other people getting from religion in passages of novels, in poems. The words transform, tame. The perspective shifts. The world alters a little, for a few moments, to make death bearable or almost bearable. Sometimes if I read bits of poems I feel stronger, shored up. Like Thomas: “That the closer I move / To death, one man through his sundered hulks, / The louder the sun blooms / And the tusked, ramshackling sea exults”; or Updike: “God save us from ever ending, though billions have. / The world is blanketed by foregone deaths, / small beads of ego, bright with appetite.”

The year I was sick and in and out of the hospital, there was one poem in particular that comforted me: WB Yeats’s “Sailing to Byzantium”. Even though I was 12, I strongly identified with his line, “That is no country for old men”. The young are in one another’s arms, the poem said, but you. You are outside all of that. “An aged man is but a paltry thing, / A tattered coat upon a stick, unless / Soul clap its hands and sing, and louder sing.”

Facebook Twitter Pinterest William Butler Yeats shown as he arrived at New York in 1932. Photograph: Bettmann/Corbis

I wrote what was probably an unnaturally impassioned English paper on the poem. I really saw myself as that aged man. This is when I was coughing up blood and telling doctors I was fine. Yeats seemed to be speaking directly to me: “Consume my heart away; sick with desire / And fastened to a dying animal / It knows not what it is; and gather me / Into the artifice of eternity.”

“Fastened to a dying animal.” That part I got. And then comes the implausible and weirdly uplifting part: There is a place called Byzantium, an eternal world of art, a place where words exist forever, out of time. The poem ends with a vision of being reborn as a golden bird, forged in an eternal fire, who lives in Byzantium and sings to lords and ladies of what is past and passing and to come. Why would that golden bird comfort me? I have no idea. The words did.

Why does it matter to me now? Why am I, in my 40s, with children still needing me to pour cereal, thinking about dying? I am talking to the frightened girl in the blue satin nightgown in the hospital, a tray with orange Jell-O and one of those little half cans of ginger ale in front of her.

I am trying to tell her that these death stories are OK. They are not really OK, because in each case someone dies, and there may, in fact, be no less-OK thing than that. But it’s OK for this reason: if you have to let go, you can. You can find or manufacture a way to.

The fear returns, or it never goes away. It remains in the form of some fierceness I know springs from those weeks in the hospital. I would not be who I am without the fear.

When I have my first baby, I go back to the hospital. The baby is one month early. The surgeon does an emergency caesarean, because I am losing amniotic fluid. The baby is four pounds but she is breathing on her own. Earlier that day, when it became clear that something was going very wrong, I had asked the sonogram technician if she could just tell me if the baby was dead or alive. She said I would have to wait and speak to the doctor, and so I waited in the hallway on a bench for the doctor for 40 minutes without knowing if the baby was dead or alive.

Maybe you are never less afraid of death; just better able to get along with the fear

For days after the caesarean, my heart rate stays dangerously elevated. The doctors can find nothing wrong with me, no pre-eclampsia, no pregnancy complication, but I can’t stop panicking. The hospital – even the happy maternity ward, with its babies wheeled in glass prams, its new mothers, shocked and queenly, shuffling their way through the halls in robes – is making me panic; any doctor who comes near me with a stethoscope around her neck makes me panic; the mysterious, undetectable thing wrong with me, which ironically is panic, makes me panic. At night, I have trouble breathing.

When the nurses measure my blood pressure, they measure it again, because they think they must have gotten it wrong. The doctors put me on a magnesium drip to slow my heart. It feels like a truck is running through my brain. The room is blurred. My thoughts are gluey, slowed. There is a chair next to my bed, where my husband should be, but he is in the office. Even though we will not separate for two and a half years, it is now that he leaves. I hold my skinny baby. I am thinking that we will die.

There is a photograph Leibovitz took of Sontag after she was dead, in the Frank Campbell funeral home; it is like a triptych, with three different photos that look almost stitched together. With a gentle light coming from below, her cropped white hair smoothed back, Sontag is lying on a table in an elegant pleated dress from Milan, wrists bruised, hands folded over her stomach, as if she had died serenely.

I know this tranquillity is highly constructed – the lighting, the careful labour of the funeral home, the dress from a designer that Sontag loved, the necklace draped around her neck, the stirring, wishful vision of the photographer – but it’s still tranquillity. The struggle, once it’s over, doesn’t exist. The fight is calmed.

I have this idea that I can work through the problem of death, the way Sendak did in drawing after drawing, and be less afraid, but maybe you are never less afraid; you are just better able to get along with the fear.

Facebook Twitter Pinterest Dylan Thomas standing near bomb-damaged buildings in Soho, London, 1945. Photograph: Popperfoto/Getty Images

Maybe the whole idea that I need to find a way to be less afraid is wrong. Maybe even the fear is tolerable. Maybe that fear is not impossible. Maybe you get through the terror because you have to get through the terror. For some reason I have unconsciously been thinking of death as something you let happen, as a partnership, an agreement you enter or wrangle your way into, which is wrong. In the actual moment, you do not have a choice. Grace finds you. Acceptance hunts you down.

I think of the letter Sendak wrote about visiting the old family friend who is dying. He is terrified of this visit. He can hardly bear the idea of it. But when he finally goes to see her, he writes about how strangely great it was. He writes that it was like gazing into something you’ve always been terrified of and finding it magnificent.

The beauty I found in these deaths was what surprised me, the life rushing in, the vastness of the work, the great, sometimes deranged-seeming courage, the mad love in the last moments. I think of Updike’s first wife, Mary, holding on to his feet in her last visit to him; of Caitlin hugging Dylan Thomas in his hospital bed, until the nurse pulled her off him; of Annie Leibovitz climbing into Sontag’s hospital bed. Part of the creative work these people did, their art, was their lives themselves. There is something glorious in the conflagration of everything at the end. The beauty was what ambushed me.

• The Violet Hour: Great Writers at the End is published by Virago in May. To order a copy for £12.99 (RRP £16.99) go to bookshop.theguardian.com or call 0330 333 6846. Free UK p&p over £10, online orders only. Phone orders min p&p of £1.99.