ExxonMobil has lost a key battle in an investigation into whether the oil giant misled the public about the dangers of climate change.

A Massachusetts judge ordered Exxon (XOM) on Wednesday to hand over more than four decades of the company's climate change research.

The court rejected Exxon's emergency motion to kill the demand from Massachusetts Attorney General Maura Healey, who is investigating allegations the company ignored internal scientific research going back to the 1970s.

The ruling came on the same day that longtime Exxon boss Rex Tillerson was being grilled by Congress about the company's climate change tactics at his secretary of state hearing. Tillerson, who stepped down last month as CEO after a decade in charge, repeatedly ducked questions about the issue from U.S. Senators.

Asked if he lacks the knowledge to respond or is simply refusing to answer, Tillerson said, "A little of both."

Last April, Massachusetts demanded Exxon turn over documents going back to 1976 related to the company's study of carbon emissions and the effects of those emissions on the climate.

This week Suffolk County Superior Court Judge Heidi Brieger upheld the attorney general's demand.

"Exxon must now end its obstructive tactics and come clean about whether it misled Massachusetts consumers and investors about what it knew about climate change, its causes and effects," the Massachusetts attorney general's office said in a statement.

However, Exxon didn't immediately signal whether it's going to comply with the order.

"We are reviewing the ruling to determine next steps," Exxon said in a statement.

Related: Tillerson ducks Exxon climate change allegations

Exxon is still awaiting a ruling in Texas, where the company has filed a complaint arguing that the Massachusetts demand for documents violates its federal constitutional rights.

In Wednesday's ruling, the Massachusetts court declined to put the proceeding on hold until the Texas court rules.

Exxon tried to kill the demand for documents by arguing the investigation is politically motivated. The company cited a March speech from Healey where she said, "We can all see today the troubling disconnect between what Exxon knew, what industry folks knew, and what the company and industry chose to share."

But the Massachusetts judge said the remarks are not evidence of "any actionable bias" and that it "seems logical" for the attorney general to inform the public about the basis of the investigation.

Climate change activists pounced on the ruling -- quickly linked it to Tillerson.

"The prospect of a sitting secretary of state becoming entangled in a lawsuit for his role in misleading the public about climate change is as real as it is alarming," said David Turnbull, campaign director for Oil Change International, an advocacy group focused on exposing the true costs of fossil fuels.

Related: Despite paper trail, Tillerson denies Exxon lobbied against sanctions

Exxon's climate change history became a flashpoint in Tillerson's confirmation hearing.

At one point, Senator Tim Kaine, Hillary Clinton's 2016 running mate, read from a 1982 letter uncovered by Inside Climate News that was written by an Exxon scientist.

"Over the past several years a clear scientific consensus has emerged regarding the expected climatic effects of increased atmospheric CO2," Roger Cohen, Exxon's former director of theoretical and mathematical sciences laboratory, wrote in the letter.

Cohen wrote that the "consensus is that a doubling of" carbon emissions from pre-industrial revolution levels would cause a rise in temperatures that would "bring about significant changes in the earth's climate."

Exxon also faces a climate change investigation from New York Attorney General Eric Schneiderman. A New York State court ordered Exxon to comply with two subpoenas last fall.

Exxon has denied allegations of funding climate change denial.

Exxon said it rejects "long-discredited conspiracy theories that attempt to portray legitimate scientific observations and differences on policy approaches as climate denial."