Over two decades, Deutsche Bank lent Donald J. Trump billions of dollars, even as his tarnished financial record put him off limits for most of Wall Street.

“You are a great friend,” Mr. Trump wrote to his Deutsche Bank contact in 1998. “We have a great relationship,” he said in 2013. “They are totally happy with me,” he declared three years later.

Now, Deutsche Bank is putting the president on the defensive.

Lawyers for the bank have spent months cooperating with investigators from two Democratic-controlled congressional committees, which issued what one lawmaker called a “friendly subpoena” to the bank in mid-April. The bank could end up sharing decades of his personal and corporate financial records.

That prospect prompted Mr. Trump to file a lawsuit in federal court in Manhattan on Monday in an attempt to block Deutsche Bank and another financial company, Capital One, from sharing documents. Mr. Trump’s lawyers said the subpoenas had no legitimate purpose and were an attempt to pry into his finances for political gain.

The heads of the two committees that issued the subpoena, Representatives Maxine Waters and Adam B. Schiff, called the suit “meritless” and an attempt to obstruct congressional oversight.

The rich trove of records held by Deutsche Bank includes internal corporate documents, descriptions of the value of Mr. Trump’s assets, and portions of his personal and business tax returns. The subpoena, issued April 15, casts a wide net for documents related to Mr. Trump’s businesses and other entities, including family trusts.

If the bank handed over even parts of Mr. Trump’s returns, it would be a dramatic end run around the president, who broke with decades of precedent by refusing to release them during the 2016 campaign.

Mr. Trump’s lawsuit puts the financially ailing Deutsche Bank in an awkward situation. The German lender’s share price has fallen substantially over the past decade, and politicians and regulators in Germany are pushing for it to make radical changes to reduce its riskiness and improve profitability. Last week, Deutsche Bank’s future became even murkier after it abandoned talks to merge with another large German lender, Commerzbank.

Mr. Trump has broadly sought to keep his finances private during his presidency. He told The New York Times in 2017 that the special counsel, Robert S. Mueller III, would cross a line by examining his family’s finances beyond any relationship with Russia.

In a sign of Mr. Trump’s sensitivity to the cache of documents held by Deutsche Bank, he erupted in anger later that year in response to news reports that Mr. Mueller had subpoenaed his records from the bank. The reports turned out to be inaccurate.

Image

President Trump filed a lawsuit in an attempt to block Deutsche Bank and another financial company, Capital One, from sharing documents.CreditErin Schaff/The New York Times

Since Democrats took control of the House of Representatives in January, Deutsche Bank officials have been working closely with investigators from the chamber’s Financial Services and Intelligence Committees to identify information that might assist their investigations into the president, according to people familiar with the discussions. They spoke on the condition of anonymity to describe private discussions.

Bank officials have told The Times that they were eager to provide the materials to Congress. In part, they said additional transparency might help squelch speculation that Deutsche Bank had served as a conduit for Russian money to get to Mr. Trump.

Despite that willingness to cooperate the bank appeared ready to leave the legal battle to House Democrats and let the courts decide what it must do.

“We remain committed to providing appropriate information to all authorized investigations and will abide by a court order regarding such investigations,” a Deutsche Bank spokeswoman, Kerrie McHugh, said in a statement.

Deutsche Bank has been cooperative with Congress in recent months. Lawyers for the bank worked with congressional staff members to narrow the scope of the subpoena to make it easier for the bank to quickly produce the requested materials, according to the people. That assistance was apparently what led Mr. Schiff, the Intelligence Committee’s chairman, to praise their cooperation and to describe the demand for materials as a “friendly subpoena.”

The subpoena demanded Deutsche Bank hand over materials related to the Trump family’s companies — including “parents, subsidiaries, affiliates, branches, divisions, partnerships, properties, groups, special purpose entities, joint ventures, predecessors, successors or any other entity in which they have or had a controlling interest.”

It also sought information about any accounts held by Mr. Trump and his immediate family, including materials that were provided to the bank when those accounts were opened. The bank has detailed financial materials on some of Mr. Trump’s children and his son-in-law, Jared Kushner, a senior White House adviser. The deadline to comply with the subpoena was May 6.

Deutsche Bank executives and congressional investigators, led by a pair of former Manhattan federal prosecutors, expected that Mr. Trump would mount a legal challenge to block the bank from complying with the subpoena, according to the people.

But bank officials have nonetheless compiled reams of materials to hand over. Included in those documents are multiple pages from each of Mr. Trump’s annual federal tax returns, which the bank received before lending him hundreds of millions of dollars for the Doral golf resort in Florida and the Old Post Office hotel project in Washington, according to current and former bank employees.

Despite the amiable history between Mr. Trump and Deutsche Bank, the lawsuit is not the first court fight between them. In fall 2008, Mr. Trump defaulted on a loan from Deutsche Bank, then sued it, claiming it had caused the financial crisis and engaged in predatory lending against him. Deutsche Bank responded by suing Mr. Trump, demanding that he immediately repay the portion of the loan, $40 million, that he had personally guaranteed.

The litigation lasted into 2010. After the suit was settled, Deutsche Bank resumed lending to Mr. Trump, dispensing more than $300 million to him over the next several years.

A version of this article appears in print on , Section A, Page 1 of the New York edition with the headline: Trump Defends Secrets in Suit Against Lender. Order Reprints | Today’s Paper | Subscribe