After starting the foundation with gifts of $356 million from 1994 to 1997, Mr. Gates, the co-founder of Microsoft, vastly expanded it into the nation’s largest with a burst of gifts totaling $24.6 billion over the next four years.

Since then, however, he has dialed back this giving. From 2002 to 2012, he gave $3.7 billion, according to foundation disclosures and data from a Gates spokesman. In that same period, he sold an estimated $22 billion in Microsoft stock.

The pullback reflects the foundation’s rapid growth — to a size that has tested its ability to give away money at the pace required both by law and by the fast-rising contributions of another donor, Warren E. Buffett.

John Pinette, a spokesman for Mr. Gates, declined to address specific reasons for the change of pace in giving, but he did point to the challenges of distributing large amounts of money where it can be most effective. Giving away $3.9 billion, as the foundation did in 2012, “is a massive task and a big responsibility,” Mr. Pinette said.

At $40.2 billion, the Gates foundation is more than triple the size of the No. 2 Ford Foundation, according to a tally by the Foundation Center, which tracks philanthropy. Such foundations generally must spend 5 percent of their assets in grants and expenses each year to maintain their tax-exempt status.

Because the vast majority of potential grant recipients are relatively small, “finding organizations that have the capacity to productively use large grants can be challenging,” said Melissa A. Berman, president of Rockefeller Philanthropy Advisors, which advises donors including the Gates foundation on how to achieve their goals. She said 75 percent of nonprofits in the United States had annual budgets of less than $500,000.

Paul Brest, a Stanford law professor and former president of the William and Flora Hewlett Foundation, said, “It’s very easy to give away money, but hard to give away money to have real and lasting impact.”

The Gates foundation has “very ambitious objectives, such as eradicating disease and improving education,” he added, and one of its greatest challenges is to decide with incomplete knowledge how best to attack such complex problems with such large sums.

Mr. Gates has recently taken a back seat to his friend Mr. Buffett in financing the foundation. Since 2006, Mr. Buffett — the chief executive of Berkshire Hathaway and the second-richest American — has given $13 billion in annual increments, after a pledge that year to give stock worth $31 billion at the time.

Mr. Buffett’s gifts require that the full dollar amounts be spent each year. The price of Berkshire stock has doubled since mid-2006, increasing the value of his annual contribution to $2 billion. One concern for Mr. Gates is that the death of Mr. Buffett, who is 83, could accelerate the pace at which the remainder of the stock he pledged, now worth $42.1 billion, would come into the foundation, further increasing its required annual spending.

Mr. Gates and Mr. Buffett have also championed philanthropic giving by their fellow billionaires. In 2010, they unveiled plans to try to persuade other wealthy Americans to pledge giving more than half their net worth to charity during their lifetimes or at their deaths.

In a public appearance in March, Mr. and Ms. Gates said they talked about giving back his wealth to society as far back as 1993, on a trip to Africa together before their marriage, when they witnessed what Ms. Gates described as “extreme poverty.” In the same appearance, Mr. Gates, who stepped aside this year as chairman of Microsoft but remains a director, repeated a past vow to eventually donate 95 percent of his wealth to the foundation, where he has devoted most of his time since 2008.

For Mr. Gates, the slower pace of contributions, along with recent gains in Microsoft’s stock price, have helped him regain the No. 1 ranking among the world’s billionaires, with a net worth estimated by Forbes at $76 billion. Mr. Pinette said there was “absolutely no connection” between the contribution tempo and the ranking. As Mr. Gates has reduced his stake to a recent 4 percent from 22 percent in 1997, Microsoft stock has generally traded at about half the peak reached in 1999 during the tech stock bubble.

While most of his personal investments mirror the kind of consumer, industrial and financial franchises favored by Mr. Buffett, some offer the same kind of hope of world betterment as his foundation.

An investor in venture capital assets managed by Vinod Khosla, an advocate of so-called clean technology, Mr. Gates has also made direct investments in some eco-friendly companies backed by Mr. Khosla. They include the power-grid software developer Varentec and the low-emission engine maker EcoMotors. Mr. Khosla followed Mr. Gates in investing in TerraPower, which aims to generate power from nuclear waste.

Some other Gates investments combine his expertise in software with disease-fighting goals that echo those of his foundation. He has invested $30 million in a drug-discovery start-up, Schrodinger. He has also invested in Nimbus Discovery, which aims to use computers to discover drugs.

The Bill & Melinda Gates Foundation, based in Seattle, has focused on fighting poverty and disease in developing nations; financing and seeking vaccines for polio, tuberculosis and malaria; and improving education in the United States. Mr. Gates has been lionized for the efforts. A “60 Minutes” segment last year on Mr. Gates showed him giving a polio vaccine to a child in Ghana. Last November, he received press coverage for a visit to Nigeria, spotlighting a recent drop in polio there.

That has not always been the case.

Twenty years ago, people associated the name Gates with “ruthless, predatory” monopolistic conduct that gave him “the reputation of a modern-day robber baron,” said Charles Lowenhaupt, a wealth adviser in St. Louis. Today, he added, Mr. Gates — after stepping back from Microsoft and throwing himself into charity work — is considered “a worldwide force for good.” His philanthropy has helped “rebrand” his name, Mr. Lowenhaupt added.

The source of the ill will was an antitrust case filed by the United States against Microsoft in May 1998 and tried between October 1998 and April 2000. It was ultimately settled in November 2001. The government contended, and an appeals court later partly agreed, that Microsoft abused its market power to maintain a monopoly in desktop computer operating systems.

During the course of that case, Mr. Gates began reducing his stake in Microsoft more aggressively and, after taking a public relations beating during the trial’s early going in late 1998, the company started what was described at the time as a “charm offensive” aimed at improving its image.

Early in the trial, the government portrayed Mr. Gates as combative, evasive or less than candid in a videotaped deposition, showing numerous excerpts from his testimony that appeared to be at odds with emails he wrote about the same events.

“The trial was a terrible black eye for Bill Gates,” said Ken Auletta, author of a 2001 book, “World War 3.0: Microsoft and Its Enemies.” At the time, Mr. Auletta said, the public relations team at Microsoft was “desperate to counter the growing impression that it was a heartless beast.”

While Mr. Auletta believes Mr. Gates’s charitable gifts were too large to be dismissed as a public relations ploy, he said that during the trial, the gifts “became part of Microsoft’s P.R. effort to humanize Gates.” Mr. Pinette, the Gates spokesman, said the burst of contributions was not intended as public relations.

Mr. Gates contributed $20.3 billion, or 71 percent of his total contributions to the foundation disclosed through 2012, during the 18 months between the start of the trial and the verdict, according to the foundation’s disclosures and data in David Bank’s “Breaking Windows,” another book about Microsoft.

Mitchell S. Pettit, formerly head of a group called ProComp backed by Microsoft rivals, said the contribution drop-off by Mr. Gates since the trial strengthened “the inference that the original motive was not altogether altruistic.”

But even critics laud Mr. Gates for the way he has thrown himself into the charity work. “Today I must say I admire the guy for what he has done,” Mr. Pettit said. “It looks like the effort is very genuine.”

A version of this article appears in print on 05/27/2014, on page B7 of the NewYork edition with the headline: As His Foundation Has Grown, Gates Has Slowed His Donations.