RICHMOND — The Virginia General Assembly has passed landmark legislation mandating a shift to renewable energy amid questions about the cost to ratepayers of expensive wind and solar projects.

The Virginia Clean Economy Act requires the state’s biggest utilities to deliver electricity from 100 percent renewable sources by 2045, sets a timeline for closing old fossil-fuel plants and mandates gains in energy efficiency.

Its passage was hailed by several environmental groups and energy technology companies that had collaborated with Democratic lawmakers on the legislation since last year.

“This is a true turning point in the climate fight here in Virginia, as we take our place among the top states in the nation working to cut emissions and move away from dirty fossil fuels,” Michael Town, executive director of the Virginia League of Conservation Voters, said in a statement.

Democrats won majorities in both chambers of the legislature last year after campaigns that called for environmental protection and challenges to the state’s biggest utility, Dominion Energy. While a more environmentally ambitious Green New Deal failed in this year’s legislative session, Democratic leaders said the Clean Economy Act delivered on their promises.

They also said the legislation will jump-start the wind and solar industries in Virginia, creating new jobs and boosting the economy.

“It’s a terrific day for Virginia,” said Del. Richard C. “Rip” Sullivan Jr. (D-Fairfax), who sponsored the House version of the bill. The legislation now goes to Gov. Ralph Northam (D), who is expected to sign it.

“The governor is thrilled to see transformative clean energy legislation pass the General Assembly,” Northam spokeswoman Alena Yarmosky said.

Dominion also worked to shape the legislation, and a company spokesman praised it Friday as “a clear path forward for Virginia’s energy future.”

Some lawmakers complained that the legislation preserves the utility’s monopoly on renewable energy and ensures that it will continue to make money at the expense of ratepayers.

“The utility has an obligation to its shareholders. We have an obligation to the ratepayers,” Sen. Richard H. Stuart (R-King George) said Thursday in debating a separate bill that had been aimed at giving the state more authority to regulate Dominion’s rates.

That bill, which would let the State Corporation Commission determine how the utility writes down the cost of closing old generating plants, passed the Senate in a rare case of a measure succeeding after being opposed by Dominion. It has also passed the House and is headed to Northam’s desk.

In debating the comprehensive energy bill, though, lawmakers from both parties questioned why it doesn’t contain more protections for consumers as Dominion takes on huge new solar and offshore wind projects. The company is building a major wind farm off the coast of Virginia Beach.

Del. Sam Rasoul (D-Roanoke) almost derailed the package on Thursday by proposing amendments aimed at reining in Dominion’s ability to pass costs on to ratepayers.

“Let’s make sure that it’s not automatically a super-high price,” Rasoul said, instead of rushing ahead with something “we can jam down people’s throats.”

His amendments, tapping into a concern shared by many Republicans, initially passed. But the Democratic majority called them up for a second vote and killed them.

Sullivan said his legislation does contain protections for consumers. He cited provisions that mandate efficiency improvements to reduce energy usage, which should keep bills down, and said the bill gives the State Corporation Commission a chance to review projects along the way.

Sen. Jennifer L. McClellan (D-Richmond), who sponsored the Senate version, said the urgency of climate change dictates that “we couldn’t afford to wait” to take action. “If we see that consumer protections in there now aren’t sufficient,” she said, “we can fix that” in future legislative sessions.