Spanish energy giant Iberdrola posted Wednesday a record profit for 2022 as growth in the United States and Brazil offset weakness in Spain.

The company said its net profit came in at 4.34 billion euros ($4.63 billion), up from 3.9 billion the previous year.

The results are higher than the 4.23 billion euros forecast by analysts, according to the financial data firm FactSet, and the 4.0-4.2 billion euros predicted by Iberdrola itself.

The energy sector has reaped gigantic profits as gas and crude oil prices spiked higher in the wake of Russia's invasion of Ukraine one year ago.

Iberdrola said its results had been boosted by the higher energy prices, especially in Brazil and the United States where it increased its tariffs, as well as by increased production of renewables.

That helped counter a 19 percent decline in net profit in its home market of Spain, where government regulations prevented the company from passing on the bulk of higher production costs to customers.

"In a very challenging environment, Iberdrola's geographic diversification has again delivered stable growth," executive chairman Ignacio Sanchez Galan said in a statement.

Iberdrola said the higher earnings had allowed it to increased its investments by 13 percent last year to 10.73 billion euros, with 90 percent allocated toward networks and renewables.

Spain's leftist government has imposed a windfall tax on energy companies for 2023 and 2024 to raise funds for measures to mitigate the impact of high energy costs and inflation, especially for low-income households.