By Dieter Holger

After other oil-and-gas companies pledged carbon neutrality this year, Repsol Chief Executive Josu Jon Imaz felt validated.

"Because of my scientific background, sometimes I doubt about everything we do," said Mr. Imaz, a chemist, in an interview.

Last year, Repsol became the first big oil company to pledge net-zero emissions by 2050 as part of a plan to move away from fossil fuels and toward renewable energy in response to climate change. BP PLC and Royal Dutch Shell PLC followed suit this year and set their own carbon-neutrality goals.

"We are not producing paper and beer," said Mr. Imaz, who took the helm of the Spanish oil company in 2014. "It is more difficult being an oil-and-gas company to make this kind of commitment. We are going to need time."

He says setting the distant 2050 target was an easier part of Repsol's climate transition while reaching its medium-term goals--a cut in carbon intensity of 20% by 2030 and 40% by 2040--is more important and challenging.

"We are not only talking about 2050," Mr Imaz said. "We have to change the company today."

Mr. Imaz, a 57-year-old who learned about climate change as a student in the 1980s, said that reaching net-zero emissions is the best way to ensure Repsol remains competitive in the greener future that investors and politicians envision.

The European Union aims to reach carbon neutrality by 2050 through a massive shift to renewable energy. On Wednesday, EU Commission President Ursula von der Leyen proposed that the bloc increase its emissions-reduction target to 55% by 2030, up from the previous goal of 40%.

As part of its climate commitment, Repsol will spend a quarter of its capital expenditure on low-carbon projects through 2025, with the majority going to renewables but also other energy sources like biofuels. This share grew to 30% this year after Mr. Imaz told Spain's Congress of Deputies last week that Repsol would invest an extra 150 million euros ($178.03 million) in a biorefinery plant in Cartagena, pending board approval.

This project and others represent around EUR840 million of the company's EUR2.8 billion capex spending in 2020, a budget it lowered by EUR1.1 billion earlier this year amid tumbling oil-and-gas prices from the economic fallout of the coronavirus pandemic.

Like many energy companies, Repsol's profit evaporated as the pandemic hammered demand for oil and gas. It posted a loss of nearly EUR2 billion in the second quarter of this year, compared with a profit of EUR525 million in the previous year.

Still, its clean energy efforts have earned recognition from analysts and nonprofits.

Repsol leads big oil-and-gas companies moving toward cleaner electricity generation, according to Citi. Analysts at the bank said that 27% of the company's growth capital is going toward electricity and other so-called new energies like liquefied natural gas, placing it ahead of Italy's Eni SpA at 24% and BP at 20%.

Analysts at Credit Suisse shared similar views, naming Repsol alongside Shell and Norway's Equinor ASA as a forerunner in the transition to a low-carbon economy based on renewable energy.

It ranked second behind Eni this year among nine big oil-and-gas companies for its alignment with the Paris Agreement on climate change, according to London-based nonprofit Carbon Tracker.

Hydrogen is key to Repsol's decarbonization plan, Mr. Imaz said. This year, Repsol said it would initially invest EUR60 million in a synthetic fuel plant that uses hydrogen made from renewables in Spain's Basque Country, where Mr. Imaz was formerly the minister of trade and industry for the regional government.

The EU, where Mr. Imaz previously served as a member of the European Parliament, has proposed directing tens of billions of dollars into hydrogen made using sun and wind power over the coming decade. By 2024, the bloc aims to up hydrogen production sixfold.

Yet Mr. Imaz said that fossil fuels will still remain part of the economy even if the goals of the Paris Agreement are met. In 2040, oil and gas could account for more than 45% of the energy mix, according to a sustainable development scenario from the International Energy Agency.

"Oil-and-gas companies have to prepare to be part of the solution," he said.

--Giulia Petroni contributed to this article

Write to Dieter Holger at dieter.holger@wsj.com; @dieterholger