Steven Mnuchin, U.S. Treasury secretary, listens during a Senate Appropriations Financial Services Subcommittee hearing in Washington D.C., U.S., on May 15, 2019.

Treasury Secretary Steven Mnuchin on Friday defied a subpoena from House Democrats to turn over six years of President Donald Trump's federal tax returns, setting up a likely court battle.

Mnuchin's refusal was not surprising. He has repeatedly argued that the Democrat-led House Ways and Means Committee did not have a "legitimate legislative purpose" to request the president's tax returns.

In a letter sent about an hour before the subpoena's 5 p.m. ET deadline, Mnuchin said that he would not authorize the IRS to give Trump's personal and business tax returns to Congress.

"In reliance on the advice of the Department of Justice, we have determined that the Committee's request lacks a legitimate legislative purpose, and pursuant to [federal tax code] section 6103, the Department is therefore not authorized to disclose the requested returns and return information," Mnuchin wrote to Ways and Means Chairman Richard Neal, D-Mass.

"For the same reasons, we are unable to provide the requested information in response to the Committee's subpoena," Mnuchin wrote.

Click here to download Mnuchin's letter to Neal

Earlier Friday, Neal told reporters on Capitol Hill that if Mnuchin and IRS Commissioner Charles Rettig blew off the subpoenas, "the result will be that we will likely proceed to court as quickly as next week."

A spokeswoman for Neal told CNBC on Friday afternoon that the timing for going to court had not yet been determined, but it "may be a while as time will be needed to prepare to file the case."

Mnuchin told a Senate panel Wednesday that he was OK with the dispute being decided by a federal court. "This is why there are three branches of government," he said.

Unlike most other presidential candidates and presidents in recent decades, Trump has refused to make his tax returns publicly available. He claimed during the 2016 campaign, and continues to claim as president, that he could not release his returns until the completion of an audit — even though there is no legal barrier to him sharing that information while being audited.

Neal argues the plain language of section 6103(f) of the federal tax code is clear: that the Treasury "shall furnish" an individual's returns if a formal written request is made.

Neal has also said that the returns are necessary as part of his committee's oversight duties and would be used as part of an effort to "assess the extent to which the IRS audits and enforces the federal tax laws against a sitting president and to determine if those audits need to be codified into federal law."

But Republicans in Congress have said that Neal's requests, along with a raft of other subpoenas lodged by Democrats against Trump and related figures, are politically motivated.

Neal made a formal request to the Treasury in early April for six years of Trump's personal and business tax returns. Mnuchin refused to hand over those documents, and blew past multiple deadlines set by the committee. Neal subpoenaed Mnuchin and Rettig for Trump's tax returns last Friday.

In a statement following Mnuchin's letter Friday, Neal said that the "issuance of these subpoenas should not have been necessary."

The law, Neal said, "provides clear statutory authority" for him to "request and receive access to tax returns and return information" — but it "does not allow for discretion as to whether to comply with a request for tax returns and return information."

Neal added: "Given the Treasury Secretary's failure to comply today, I am consulting with counsel on how best to enforce the subpoenas moving forward."

Mnuchin said that week that he had not discussed the subpoenas with anyone at the White House — including Trump, who has vowed to fight "all the subpoenas" lodged by Democrats.

— CNBC's Dan Mangan contributed to this report.