California is racing to secure large amounts of power in the next few years to make up for the impending closure of fossil-fuel power plants and a nuclear facility that provides nearly 10% of the state’s electricity.

The California Public Utilities Commission has ordered utilities to buy an unprecedented amount of renewable energy and battery storage as the state phases out four natural-gas-fired power plants and retires Diablo Canyon, the state’s last nuclear plant, starting in 2024.

While the companies are moving quickly to contract for power, the California Energy Commission and the state’s grid operator have recently expressed concern that the purchases may not be enough to prevent electricity shortages in coming summers.

The order requires companies such as PG&E Corp. PCG 3.99% and Edison International’s EIX 1.33% Southern California Edison to bring more than 14,000 megawatts of power generation and storage capacity online in the coming years, an amount equal to roughly a third of the state’s forecast for peak summer demand.

The state’s dilemma underscores the difficulties of rapidly transitioning to cleaner power resources, as the U.S. and many countries are now pledging to do in response to concerns about climate change. A California law passed in 2018 requires the state to decarbonize its power grid by 2045.

Edward Randolph, the California utility commission’s executive director for energy and climate policy, said the body has been preparing for Diablo Canyon’s retirement since it approved PG&E’s plan to decommission the nuclear plant in 2018. But the commission has since had to revise its planning as a result of a change in the amount of power available throughout the West, he said.

The drought has constrained the output of some of the region’s most significant generating facilities, including the Hoover Dam. On top of that, other states have moved to close coal-fired power plants in recent years, reducing the amount of electricity California can import when high temperatures boost electricity demand.

“What changed dramatically…is we have had significantly bigger and more West-wide heat waves than ever before,” Mr. Randolph said. “Those aren’t built into our planning standards.”