LONDON — BP had been at the forefront when it came to major oil companies going green. It invested billions in renewables. It was quick to acknowledge the link between fossil fuels and global warming. It adopted the slogan “Beyond Petroleum.”

But that all fell by the wayside when the company was hit by the 2010 Gulf of Mexico oil spill. On Friday, in what may be a move to repolish tarnished green credentials, the energy giant said that it would spend $200 million to acquire a large stake in a Lightsource, a solar power developer based in Britain.

BP, like other major European oil companies, is responding to pressure from investors and governments, especially in the region, to shift away from the traditional fossil fuels blamed for climate change, like oil and gas, and into cleaner sources of energy. Statoil, the Norwegian giant, for example, is staking out a big position in offshore wind, and Total, the French company, last year bought a battery maker called Saft for 950 million euros, or $1.1 billion.

“The European majors feel under pressure to diversify, to get exposure to different technologies so they are not left out,” said Valentina Kretzschmar, an analyst at energy consultants Wood Mackenzie. “It is what a lot of their peer group is doing.”