Elon Musk and Jamie Dimon don’t get along.

Mr. Musk has spurned Mr. Dimon’s JPMorgan Chase & Co. for years, turning to other banks while expanding Tesla Inc. and his broader empire. Conversations over the years between the two companies have often upset one side or the other, according to people familiar with the matter.

Messrs. Musk and Dimon...

Elon Musk and Jamie Dimon don’t get along.

Mr. Musk has spurned Mr. Dimon’s JPMorgan Chase & Co. for years, turning to other banks while expanding Tesla Inc. and his broader empire. Conversations over the years between the two companies have often upset one side or the other, according to people familiar with the matter.

Messrs. Musk and Dimon have tried to patch things up but clashed instead, the people said. JPMorgan decided some time ago that it is better off without Tesla, according to people familiar with the matter.

A small part of the quiet feud, which pits America’s most valuable car maker against its biggest bank, spilled into the open last week when JPMorgan sued Tesla. In its lawsuit, JPMorgan said Tesla owes it $162 million from a trade the bank helped arrange in 2014. Typically, bankers seek to avoid public fights with big clients and even potential clients, anxious about winning fees and worried the slightest insult could cost them access.

“We have provided Tesla multiple opportunities to fulfill its contractual obligations, so it is unfortunate that they have forced this issue into litigation,” JPMorgan said last week.

“If JPM doesn’t withdraw their lawsuit, I will give them a one star review on Yelp,” Mr. Musk said in response to The Wall Street Journal. “This is my final warning!”

Both chief executives are commanding presences inside their companies and industries. And both have had public fights with rivals or sharp words for critics and regulators, though Mr. Dimon has often wound up expressing regret over what he admits are uncareful slips while Mr. Musk has rarely backed down.

Tesla has captured the market’s imagination about the future of electric cars and become one of the first companies valued at more than $1 trillion, making it the kind of client Wall Street fights over.

JPMorgan’s investment bankers haven’t worked on any Tesla offering or transaction since 2016, according to public records. When JPMorgan worked on Tesla’s 2010 initial public offering of stock and several capital-markets transactions in the following years, it was usually ranked behind rivals such as Goldman Sachs Group Inc.

and Morgan Stanley.

JPMorgan has been paid about $15 million by Tesla for advice and capital-markets work in the past decade, while Goldman has made about $90 million, according to Dealogic.

Mr. Musk has used Morgan Stanley, Goldman and Bank of America Corp. for the personal loans he has pledged his stockholdings against, according to public filings.

JPMorgan’s Chase consumer bank is a big auto lender, but it was hesitant to be an early backer of Teslas and other electric vehicles, people familiar with the matter said. Bankers raised concerns about the long-term value of electric-vehicle batteries.

SHARE YOUR THOUGHTS

Who would you rather have running a company: Jamie Dimon or Elon Musk? Why? Join the conversation below.

Later, Chase executives approached Mr. Musk about an agreement to make Chase the primary lender to Tesla buyers at dealerships, the people said. The bank has similar deals with Maserati and Jaguar Land Rover. Mr. Musk said no, the people said.

The bank recently signed a similar pact with a Tesla rival, the electric-truck maker Rivian Automotive Inc. It has also been financing more Teslas recently for its customers, the people said.

Last week’s lawsuit is likely to increase the tension. Tesla will be represented by Alex Spiro,

the lawyer who successfully defended Mr. Musk in a defamation lawsuit.

At the heart of the lawsuit are warrants that JPMorgan bought from Tesla as part of a large set of trades it helped set up for the company in 2014. Tesla would have to pay JPMorgan, in cash or stock, if the stock was trading above the agreed-upon price when the warrants expired in 2021.

The contract, JPMorgan said, allowed JPMorgan to change that strike price if Tesla announced it was exploring a sale or other transactions, because that would affect the value of the warrants.

In 2018, Mr. Musk tweeted that he had secured funding to take Tesla private at $420 a share. JPMorgan lowered the strike price and alerted Tesla, according to its lawsuit. When it became apparent there was no deal, JPMorgan moved the strike price higher again, but not all the way back to the original price.

Tesla objected, according to the lawsuit, telling JPMorgan that its price adjustments were “unreasonably swift” and “opportunistic.”

Tesla also told JPMorgan it was the only bank making such an adjustment, according to the lawsuit. JPMorgan said the other banks “may have declined to adjust their warrants for business reasons having nothing to do with the contractual terms or the reasonableness of JPMorgan’s adjustments.”

By the time the contracts started expiring in June 2021, the stock price had soared and was above both the original and the adjusted prices. JPMorgan requested payment and Tesla paid JPMorgan based on the original strike price. It refused to pay the extra amount the adjustments would have required, the bank said.

Write to David Benoit at david.benoit@wsj.com