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.