Vartan Gregorian, the Iranian-born historian and educator who transformed the New York Public Library from a broke and derelict institution into a thriving center of culture and learning and who pushed tirelessly for improving access to knowledge through his leadership of Brown University and the grantmaking Carnegie Corp., died April 15 in New York City. He was 87.

The Carnegie Corp. announced his death in a statement, which said he had been hospitalized for testing related to stomach pain.

Born into an Armenian Christian family in northwestern Iran, Dr. Gregorian was raised largely by his grandmother, an illiterate peasant who taught him that “learning was the only way one can escape one’s condition,” he recalled to Voice of America. At 11, he started working as a page in the library of the local Armenian church, and his love of books took root.

When he arrived in New York in 1956, a shy and lonely scholarship student, one of his first stops was the palatial New York Public Library on Fifth Avenue. “Suddenly I realized that nobody had asked any identification or permission for me to enter,” he later told NPR. “So quietly, I left.” He didn’t realize that the library was free and open to all.

By the time he became its president 25 years later, he had earned a doctorate in history from Stanford University and taught at the University of Texas and the University of Pennsylvania, where he served as a dean and then provost.

Passed over for the presidency of Penn, Dr. Gregorian accepted the position of president and chief executive of New York’s library system in 1981 “with trepidation” and against the advice of most of his friends, he wrote in his well-received 2003 memoir, “The Road to Home.”

New York City was just emerging from a decade-long financial crisis that had brought it to the brink of bankruptcy and decimated public services — including the library system’s four research libraries and 80-plus branches. In the flagship building, grime caked the marble lobby, the chandeliers housed burned-out bulbs, and precious old books crumbled in the stacks without air-conditioning.

Dr. Gregorian quickly won over the demoralized librarians by addressing them as “my fellow educators.” He considered his new role “a mission, not a job,” he wrote, and saw the library as nothing less than “the cradle of democracy and knowledge.”

Short and stout with merry eyes and a disarming smile, Dr. Gregorian brought boundless energy and enthusiasm to his fundraising duties. He and his wife, Clare, became fixtures on the New York social scene, attending dinners with luminaries such as Mayor Edward I. Koch, Jacqueline Kennedy Onassis, Isaac Bashevis Singer and Brooke Astor, the honorary chairwoman of the library’s board who donated nearly $25 million and became a close friend.

Dr. Gregorian’s excitement occasionally veered into overzealousness. “Sometimes he talks too much, no question about that,” Astor told the New Yorker in 1986. “He’s a spinner of tales, and when he’s wound up, it’s hard for him to stop.”

During his eight-year tenure, the library raised more than $325 million, doubled its operating and acquisitions budgets and undertook extensive structural renovations and repairs — including a $45 million restoration of the flagship Beaux-Arts building and the reclamation of seedy Bryant Park next door.

It installed climate-controlled stacks, added 400 employees, began digitizing its holdings and created new programs and cultural events. Dr. Gregorian reestablished the library “as an intellectual center, magnet — and jewel,” Library Journal noted in 1988. “In a word, he made support of the library fashionable.”

Eager to return to academia, Dr. Gregorian assumed the presidency of Brown University in 1989. He wasted no time in using his new platform to blast “the woeful inadequacies of our public school system,” as he said in his inaugural address, arguing that universities should not have to focus on “remedial work.”

The goal of all postsecondary education — whether at a community college or an Ivy League university such as Brown — was to provide foundational liberal arts training to help students “learn to learn,” he once told Humanities magazine. The true message of a diploma, Dr. Gregorian said, should be, “Congratulations for knowing this much, and now we instruct you to learn for the rest of your life.”

Under his leadership, Brown raised more than $500 million, nearly tripling its endowment. Applications soared.

But Dr. Gregorian grew frustrated by campus politics, and he had no patience for faculty pettiness or backbiting. “Let me put it delicately,” he told Humanities, describing the difference in running a library versus a university. “Books don’t talk back.”

In 1997, after eight years at Brown, he was again ready to move on. At Carnegie Corp. of New York, he traded the rigors of raising money for those of giving it away. Andrew Carnegie — like Gregorian, a poor, book-loving immigrant who found meteoric success in America — established the philanthropic foundation in 1911 to “promote the advancement and diffusion of knowledge and understanding.”

As its 12th president, Dr. Gregorian’s mission was to allocate funds within its three main focus areas: education, democracy and international peace and security.

“I thought it would be easy to come here and just write checks, but I found it just as difficult as being a fundraiser,” he said to Humanities. “Actually, it’s harder . . . because you have so many excellent projects that compete for funding.”

He pushed back against criticism, levied most forcefully in a 1997 report by a private commission headed by former education secretary Lamar Alexander, that foundations like his were ineffectual extensions of big government, addressing “broad social theories” instead of “concrete problems.”

“Foundations were created to do things that government could not,” Dr. Gregorian argued in an interview with the New York Times, such as study issues, ask questions and stimulate discussion — not to pick up the slack when Washington cuts social programs.

He presided over Carnegie for more than two decades, becoming a de facto expert on philanthropic giving and an unpaid adviser to billionaires Walter Annenberg, Ted Turner, and Bill Gates. “He’d come and see me, and we’d talk about what were good causes, or what was going on with foundations,” Gates, the Microsoft co-founder, told the Times. Those meetings helped shape the Bill & Melinda Gates Foundation’s campaign to improve global health.

Dr. Gregorian received a National Humanities Medal from President Bill Clinton in 1998 and was awarded the Presidential Medal of Freedom, the nation’s highest civilian honor, by President George W. Bush in 2004.

Vartan Gregorian was born in Tabriz, Iran, on April 8, 1934. His father worked as a middle manager for an oil company and often lived away from home. Vartan’s mother died when he was 6. Desperate to soften the blow, his relatives told him and his younger sister that she was simply “undertaking a long journey” to “America, a beautiful, faraway land,” he wrote in his memoir, fueling his vision of the United States as a welcoming paradise.

His grandmother became the guiding force of his childhood, telling aphoristic stories, instilling manners and morals and always encouraging education. When Vartan was 14, he was offered the opportunity to attend an Armenian school in Beirut.

He excelled at his studies, spoke seven languages and completed his undergraduate degree at Stanford in two years, in 1958. He stayed on for graduate school, receiving dual doctorates in history and humanities in 1964.

In 1960, he married Clare Russell, whose ancestors — on both sides — had come to America aboard the Mayflower. She “played an entrancing Joplin ragtime,” Dr. Gregorian once told the New Yorker.

She died in April 2018. Survivors include their three sons, Vahé Gregorian of Kansas City, Mo., Raffi Gregorian of New York City and Dareh Gregorian of Brooklyn; a sister; and five grandchildren.

After teaching briefly at San Francisco State and the University of Texas, Dr. Gregorian went to Penn, where he raised millions as an administrator even as he continued to grade his students’ blue booklets.

He wanted — and was widely expected — to succeed Penn President Martin Meyerson when he resigned in 1981. But the search committee named Tulane President Sheldon Hackney to the position. Dr. Gregorian received the news on his car radio; stung, he abruptly resigned. “Defeat, I’ve never minded,” he told the Times. “Insult, I have.”

In his memoir, Dr. Gregorian recounted the assessment of some Penn trustees that he was “too ethnic,” with his “thick accent” and “unruly hair,” and lacking in “social graces” to become president. In a 1986 interview with the New Yorker, he called his stint at Penn “the most exhilarating and most painful experience of my entire life.”

By contrast, he considered the New York Public Library his most important — and rewarding — job. “New York was full of chutzpah and I was full of chutzpah,” he wrote, explaining why he accepted such a daunting assignment. “We would do our best.”