Ebocha, Nigeria — Justice Eta, 14 months old, held out his tiny thumb.

An ink spot certified that he had been immunized against polio and measles, thanks to a vaccination drive supported by the Bill & Melinda Gates Foundation.

But polio is not the only threat Justice faces. Almost since birth, he has had respiratory trouble. His neighbors call it "the cough." People blame fumes and soot spewing from flames that tower 300 feet into the air over a nearby oil plant. It is owned by the Italian petroleum giant Eni, whose investors include the Bill & Melinda Gates Foundation.

Justice squirmed in his mother's arms. His face was beaded with sweat caused either by illness or by heat from the flames that illuminate Ebocha day and night. Ebocha means "city of lights."

The makeshift clinic at a church where Justice Eta was vaccinated and the flares spewing over Ebocha represent a head-on conflict for the Gates Foundation. In a contradiction between its grants and its endowment holdings, a Times investigation has found, the foundation reaps vast financial gains every year from investments that contravene its good works.

In Ebocha, where Justice lives, Dr. Elekwachi Okey, a local physician, says hundreds of flares at oil plants in the Niger Delta have caused an epidemic of bronchitis in adults, and asthma and blurred vision in children. No definitive studies have documented the health effects, but many of the 250 toxic chemicals in the fumes and soot have long been linked to respiratory disease and cancer.

"We're all smokers here," Okey said, "but not with cigarettes."

The oil plants in the region surrounding Ebocha find it cheaper to burn nearly 1 billion cubic feet of gas each day and contribute to global warming than to sell it. They deny the flaring causes sickness. Under pressure from activists, however, Nigeria's high court set a deadline to end flaring by May 2007. The gases would be injected back underground, or trucked and piped out for sale. But authorities expect the flares to burn for years beyond the deadline.

The Gates Foundation has poured $218 million into polio and measles immunization and research worldwide, including in the Niger Delta. At the same time that the foundation is funding inoculations to protect health, The Times found, it has invested $423 million in Eni, Royal Dutch Shell, Exxon Mobil Corp., Chevron Corp. and Total of France — the companies responsible for most of the flares blanketing the delta with pollution, beyond anything permitted in the United States or Europe.

Indeed, local leaders blame oil development for fostering some of the very afflictions that the foundation combats.

Oil workers, for example, and soldiers protecting them are a magnet for prostitution, contributing to a surge in HIV and teenage pregnancy, both targets in the Gates Foundation's efforts to ease the ills of society, especially among the poor. Oil bore holes fill with stagnant water, which is ideal for mosquitoes that spread malaria, one of the diseases the foundation is fighting.

Investigators for Dr. Nonyenim Solomon Enyidah, health commissioner for Rivers State, where Ebocha is located, cite an oil spill clogging rivers as a cause of cholera, another scourge the foundation is battling. The rivers, Enyidah said, "became breeding grounds for all kinds of waterborne diseases."

The bright, sooty gas flares — which contain toxic byproducts such as benzene, mercury and chromium — lower immunity, Enyidah said, and make children such as Justice Eta more susceptible to polio and measles — the diseases that the Gates Foundation has helped to inoculate him against.

Investing for profit

AT the end of 2005, the Gates Foundation endowment stood at $35 billion, making it the largest in the world. Then in June 2006, Warren E. Buffett, the world's second-richest man after Bill Gates, pledged to add about $31 billion in installments from his personal fortune. Not counting tens of billions of dollars more that Gates himself has promised, the total is higher than the gross domestic products of 70% of the world's nations.

Like most philanthropies, the Gates Foundation gives away at least 5% of its worth every year, to avoid paying most taxes. In 2005, it granted nearly $1.4 billion. It awards grants mainly in support of global health initiatives, for efforts to improve public education in the United States, and for social welfare programs in the Pacific Northwest.

It invests the other 95% of its worth. This endowment is managed by Bill Gates Investments, which handles Gates' personal fortune. Monica Harrington, a senior policy officer at the foundation, said the investment managers had one goal: returns "that will allow for the continued funding of foundation programs and grant making." Bill and Melinda Gates require the managers to keep a highly diversified portfolio, but make no specific directives.

By comparing these investments with information from for-profit services that analyze corporate behavior for mutual funds, pension managers, government agencies and other foundations, The Times found that the Gates Foundation has holdings in many companies that have failed tests of social responsibility because of environmental lapses, employment discrimination, disregard for worker rights, or unethical practices.

One of these investment rating services, Calvert Group Ltd., for example, endorses 52 of the largest 100 U.S. companies based on market capitalization, but flags the other 48 for transgressions against social responsibility. Microsoft Corp., which Bill Gates leads as board chairman, is rated highly for its overall business practices, despite its history of antitrust problems.