If ever a treasure could be described as long lost, the 665 pages of handwritten papers that Barbara Testa discovered inside a trunk in the attic of her California home in 1990 was one. “The minute I found it,” the Los Angeles Times quoted her as saying, “I just had a feeling.”

She had stumbled upon the first half of the manuscript of Mark Twain’s 1884 novel “Adventures of Huckleberry Finn,” the story of a runaway boy, Huck, and a runaway slave, Jim, whose trip together down the Mississippi River became one of the most enduring narratives in American literature.

The manuscript’s journey to Mrs. Testa’s attic — and its ultimate deposit in a New York library where, to the relief and thrill of Twain scholars and aficionados, it was reunited with its other half — made her a protagonist in a modern-day literary drama.

Mrs. Testa died Dec. 16 at her home in Boulder Creek, Calif. She was 91 and had congestive heart failure, said her daughter Laura Testa-Reyes.

A librarian whose father had been a mystery writer, Mrs. Testa spent her life ensconced in books. Her family’s literary inclinations could be traced at least to her paternal grandfather, James Fraser Gluck, a lawyer who in the latter 1800s began soliciting original manuscripts from authors of the era to build the collections of the institution that today is the Buffalo and Erie County Public Library.

In the course of that work, Gluck entered into correspondence with Twain — the pen name of Samuel L. Clemens — who agreed to donate the manuscript of “Huck Finn,” or at least what he then believed remained of it, to the library. In 1885, he sent the second half of the manuscript, comprising 695 pages, explaining that the first half had been lost.

Seventeen months later, according to extant correspondence, Twain found and sent the other half of the manuscript to the library. But for reasons that remain unknown, that portion was never entered into the collection. Gluck died in 1897, and the manuscript’s whereabouts remained unknown until Mrs. Testa began rifling through her attic a century later.

The unearthing of the “Huck Finn” manuscript was “the most exciting discovery of Mark Twain material in my entire career — and probably in several careers if I had them,” Robert Hirst, head of the Mark Twain Papers archive at the University of California at Berkeley, said in an interview.

“It is something that scholars didn’t expect to happen,” he said. “We’re talking about Mark Twain’s masterpiece, his absolute best work, far and away above anything else that he wrote.”

In the famous final lines of the novel, Huck declares that “I reckon I got to light out for the Territory,” lest his Aunt Sally try to “sivilize” him. When news of the discovery became public, William H. Loos, curator of the rare-book room at the Buffalo library, remarked to the New York Times on the irony of the manuscript’s arrival in California.

“Huck went to Hollywood,” he said. “It’s bizarre, but Huck’s wish . . . to ‘light out for the Territory,’ to go West, came true.”

The manuscript continued on its journey — transported by armored car and jet — to the Sotheby’s auction house in New York, where its authenticity was confirmed. At the time, its estimated value was $1.5 million.

A legal dispute ensued, pitting Mrs. Testa and her sister against the Buffalo library. USA Today described the battle as “the biggest tug of war over a document’s ownership since Richard Nixon claimed presidential papers as his personal property.”

Through a private sale of the manuscript, the sisters could have sold single pages to individual collectors, a course that would have maximized their profits, according to experts, but dispersed the manuscript perhaps beyond any possibility of reconstitution.

But the sisters said in a statement at the time that they were “sympathetic to the possibility of reuniting the manuscript” and ultimately reached an undisclosed settlement in which, in 1992, their half of the manuscript was given to the library.

“Not everyone would have been quite so principled,” Hirst said.

Barbara Ellen Gluck was born in Los Angeles on Aug. 15, 1928. Her father wrote mystery stories, aspiring to adapt them for Hollywood, and her mother worked for Disney and later Warner Bros. painting animation cels.

Mrs. Testa received a bachelor’s degree in Spanish from Los Angeles State College, now California State University at Los Angeles, in 1951 and a master’s degree in library science from the now-defunct Immaculate Heart College in Los Angeles in 1969, according to her daughter. She later worked as a reference and children’s librarian.

Her husband of 45 years, Frank Testa, died in 2000. Survivors include four children, Jim Testa of Palo Alto, Calif.; Lou Testa of Beaverton, Ore.; Laura Testa-Reyes of Boulder Creek; and Kitty Schaller of Pasadena, Calif.; as well as a sister and six grandchildren.

Whatever its monetary value, the literary value of the long­hidden Twain treasure far exceeded it in the eyes of literature professors and admirers of the writer’s fiction.

Matthew Seybold, a Twain scholar and professor at Elmira College in New York, observed in an email that the newly discovered manuscript helped scholars in three ways. First, it allowed them to determine when various sections of the novel were written and which people and events may have influenced Twain’s thinking at the time; second, it allowed scholars to identify changes, intentional or not, made before the book was published; and, finally, it helped reveal Twain’s sense of purpose in his work and the extent to which Huck Finn was “a realization of his artistic vision.”

In his revisions, Twain fine-tuned the language that became a calling card of his young unlettered protagonist — eliminating highfalutin alliterations, rendering the contraction “wasn’t” in the more vernacular “warn’t” and replacing the French-derived “forest” with the Anglo-Saxon “woods.”

“You realize that this is not some natural genius who just tosses it off. This is somebody who had to work to achieve the effect that everyone says is so wonderful,” Hirst said. “ ‘Woods’ — who would think of that? But he did. He very carefully removed all the ‘forests.’ ”

In a celebrated passage in which Huck describes a sunrise, Twain amended the depiction to make it less sentimental, for even amid the beauty, the breeze might bring with it the stench of “dead fish laying around, gars, and such, and they do get pretty rank.”

He excised a long passage in which Jim recounts to Huck a frightening encounter with a corpse and professes his belief in ghosts.

Twain eliminated those pages, Hirst contends, because he did not desire to traffic in a prevailing stereotype of black people as superstitious. Rather than the racist work that some critics allege it to be, “Huck Finn” is a powerful argument against racism, Hirst said, “if you know how to read it.”

As for Twain and how he might have felt about the resurrection of his manuscript, Hirst said that the author, in all probability, would have been pleased. He had a “lifelong habit of denouncing the proofreaders and typesetters” who at times took it upon themselves to make what they regarded as improvements to his punctuation.

Twain did not see those changes as improvements. Once, upon learning of such a liberty taken by a proofreader, he wrote to a friend: “I telegraphed orders to have him shot without giving him time to pray.”