KABUL, Afghanistan — Nancy Hatch Dupree, an American writer and historian who arrived in Afghanistan in 1962 and devoted decades of her life to preserving the country’s heritage during some of its darkest times, died in Kabul on Sunday. She was 89.

Her death was announced by the Afghanistan Center at Kabul University.

Weakened by a leg injury and a failing heart and lungs, but resistant to returning to the United States for treatment, Mrs. Dupree had been focusing on what would become her final project: cataloging thousands of photos, some from the early years she and her archaeologist husband, Louis Dupree, spent traveling Afghanistan — she writing guidebooks, he excavating its ancient past.

Mrs. Dupree wrote five books, and more than 100 articles and pamphlets, on Afghanistan. Her legacy, which she often described as the completion of her husband’s vision, is an academic oasis: the Afghanistan Center, a state-of-the-art research hub that houses more than 100,000 items of primary and secondary sources.

Mrs. Dupree bore witness to decades of history, but perhaps the greatest dangers she overcame were during the period of Taliban rule, from 1996 to 2001.