Nestlé, the world's biggest food manufacturer, says it will make the palm oil in its best-selling chocolate bars more eco-friendly, after a guerrilla campaign against it on the internet.

The Swiss confectionery-to-coffee giant said it was inviting a not-for-profit group to audit its supply chain and promised to cancel contracts with any firm found to be chopping down rainforests to produce the vegetable oil, which it uses in KitKat, Aero and Quality Street.

The concession followed a three-month campaign by the environmental group Greenpeace, which led to Nestlé being attacked on social networking sites such as Facebook and YouTube. One million people watched Greenpeace's spoof advert for KitKat, despite its being taken off YouTube temporarily after a legal threat.

As well as illustrating the vulnerability of multinational companies to new media campaigns by NGOs which can galvanise individuals in a way that was impossible before the creation of the internet, the campaign also illustrated the intense environmental controversy surrounding palm oil.

Thousands of hectares of rainforests in Malaysia and Indonesia have been cleared to make way for oil palm plantations, depriving tribes of ancestral lands, increasing climate change emissions and killing rare animals such as the Sumatran tiger, sun bear, clouded leopard and pangolins. Campaigners have particularly stressed the damage done to orangutans, a close relative of man which lives only on the heavily deforested islands of Borneo and Sumatra.

Since The Independent disclosed the presence of palm oil in 43 of the UK's top-selling grocery brands, companies such as Nestlé, Marks & Spencer, Cadbury and Mars have committed to moving to a sustainable supply.

But Nestlé had been a relatively slow mover, promising only to meet the latest acceptable date of 2015 set by the World Wildlife Fund for moving to supplies certified sustainable by the Roundtable on Sustainable Palm Oil.

On 17 March, Greenpeace began a campaign against Nestlé, launching an early morning protest at its UK headquarters in Croydon, Surrey, and posting its one-minute Have a Break? "advert" on the internet. It showed an office worker biting into a KitKat containing an orangutan finger, which dripped blood onto a computer keyboard.

"Indonesian forests are being torn down to grow palm oil, which is the vegetable fat of choice for companies worldwide, including Nestlé," Greenpeace complained. "But while many companies such as Unilever and Kraft are making efforts to disassociate themselves from the worst practices of the palm oil industry, Nestlé has done diddly squat."

The action group claimed it had uncovered evidence that the Indonesian palm oil supplier Sinar Mas – which it said supplied Nestlé – had been involved in continuing deforestation. Nestlé denied it bought oil from Sinar Mas but said it would ask its supplier, Cargill, to investigate the claims. That was not enough to stop the campaign.

Members of the public posted angry messages on Nestlé's Facebook page – substituting the word Killer for KitKat; anti-Nestlé campaign groups such as Baby Milk Action and Nestlé Critics took up the cause; and hundreds of thousands of people watched the grisly Have a Break? video.

On 15 April, Greenpeace disrupted Nestlé's annual general meeting in Lausanne. Protesting "orangutans" met arriving shareholders and, inside the building, activists hidden in the ceiling unfurled banners with the message: "Nestlé, give the orangutans a break".

Apparently braced for the protests, the company's chairman, Peter Brabeck, defended the company's position, saying Nestlé only used 320,000 tonnes of palm oil a year, slightly under one per cent of global production and less than the 500,000 tonnes used for bio-fuel in the UK and Germany. To applause, rather than blaming Nestlé for deforestation in Indonesia, he blamed a "political decision" to use palm oil as a bio-fuel. The protests continued.

On Monday, Nestlé announced what Greenpeace hailed as a "positive step" – the auditing of its supply chain by the Geneva-based Forest Trust. The company said: "By setting critical requirements for its procurement process and checking compliance with our supplier code, Nestlé wants to ensure that its products have no deforestation footprint." The company intended to source 18 per cent of its palm oil from "sustainable sources" this year and 50 per cent by the end of 2011.

Scott Poyntor, the Forest Trusts's executive director, said the commitment was a "game changer". "For the first time, a global company is saying it doesn't want its products to have a deforestation footprint, and is taking action to live up to its words," he said.

Greenpeace welcomed the agreement, which it warned it would closely monitor. "Online and offline the message to Nestlé has been strong and relentless over the past two months," it told its supporters.

"All of it – from protesting orangutans on the streets to Facebook status updates – has brought us to today's commitment."

Who's going green – and when

The dates by which firms say they will have all their palm oil supply certified sustainable by the Roundtable on Sustainable Palm Oil.

2011 United Biscuits

2012 Unilever, Waitrose

2014 Sainsbury's, Cadbury

2015 Marks & Spencer, Mars, Co-op, Tesco, Asda, Nestlé, Procter & Gamble, Allied Bakeries