Compromise and ambitious goals, it turns out, are not always mutually exclusive.

On Friday, Gov. Charlie Baker signed a landmark climate bill that puts Massachusetts on a path toward net-zero carbon emissions by 2050.

The legislation, which has been ping-ponging around Beacon Hill for some time, is often referred to as the climate roadmap bill. It not only establishes an emissions target for the state over three decades, but also sets the mile markers along the way with interim goals for the state as well as sector-specific emissions limits across six domains including transportation and electric power. The law would also see the state adopt new energy efficiency standards for appliances, increase offshore wind energy production, develop a specialized net-zero building construction code for municipalities that want it and strengthen protections for communities facing greater health risks from pollution.

This is a big step forward for Massachusetts’ part in what should be a national — ideally international — effort to stave off a looming climate crisis, the full brunt of which our children and grandchildren will face if we are complacent. The Bay State has always been a leader in environmentalism and green efforts, and this climate roadmap will continue that tradition.

No one on Beacon Hill is getting exactly what they wanted here in a bill that has taken several tries to get over the goal line. In January, Gov. Baker pocket-vetoed an initial version, and when the Legislature sent another to his desk, the governor returned it with proposed amendments. The Legislature incorporated some, though not all, of those amendments and put the bill before the governor again, and that’s the version he signed Friday. Notably, the Legislature acquiesced to slightly loosening enforcement of sector-specific emissions sublimits, so that the executive branch would not be held legally liable if one sublimit is not met in a year in which the state’s overall target was met. Gov. Baker, on the other hand, saw one of his more substantive amendments rejected — one that would have softened the state’s 2030 emissions stretch goal.

While some may favor an “uncompromising” approach to pressing, large-scale issues like climate change, the Legislature and the Baker administration should be commended for working through their differences while still seeing eye-to-eye on the pressing need to significantly reduce carbon emissions and make Massachusetts’ energy picture more sustainable. For his part, Gov. Baker is bucking the mainline ideology of his own party just by acknowledging that human-caused climate change is real and aiming to do something about it. Indeed, it’s somewhat ironic that one of the most aggressive emission-reduction measures by a U.S. state has been signed into law by a Republican governor.

Obviously, Massachusetts can’t do this alone. To put up a real fight against the existential threat of climate change, we need action at the federal level and cooperation at the international level.

Hopefully, however, Massachusetts can lead the way, as it has so often before when it comes to the environment, climate and green energy. Meanwhile, Joe Biden’s administration is currently at work formulating a massive infrastructure package that could lay the groundwork for meaningful action at the national level, though its path forward through Congress will be politically perilous at best.

With this new climate law, the commonwealth has set an ambitious but necessary goal and charted the road to get there amid divided government. With Massachusetts as a model, perhaps the next ambitious goal is getting Washington to do the same.