© MITCHELL LEVY/Globe Photos/Zuma Press

Party and politics aren’t all that distinguish the billionaire New Yorker in the White House from the one seeking to displace him.

President Trump’s Fifth Avenue apartment in Manhattan’s Trump Tower feels “like you’re walking into a casino. Very lavish. A lot of gold,” said John Catsimatidis, another billionaire New Yorker. He also has visited Michael Bloomberg’s New York City townhouse. “You walk into Bloomberg’s home on 79th Street, it’s like Louis XIV’s home,” he said. “Very conservative.”

Mr. Trump, 73 years old, and Mr. Bloomberg, 78, lived about 20 blocks apart on Manhattan’s East Side and miles apart in sensibility, say dozens of people who know them. Mr. Trump was seen as a celebrity whose marriages and divorces splashed across newsstand tabloids. Mr. Bloomberg was the data-driven businessman who served three terms as New York’s mayor.

“Mike’s more intellectual, more of a refined billionaire,” said Don Peebles, a real-estate developer. “Donald’s more of a blue-collar billionaire.”

Mr. Bloomberg was raised in a working-class family outside of Boston and made his fortune selling data to Wall Street traders. Once established, he circulated easily in Manhattan’s philanthropic circles, boardrooms and elite clubs.

Get news and analysis on politics, policy, national security and more, delivered right to your inbox

The president grew up in a wealthy New York real-estate family. He never fit among the city’s old-money crowd, which viewed him more as a showman than a successful developer.

Mr. Bloomberg appears on the ballot for the first time in the Democratic primary contest on Tuesday, when more than a dozen states hold contests. He spent more than $600 million on his presidential campaign.

For years, the two billionaires coexisted peacefully in the city, trading pleasantries in public when it suited them. Some of their children became friends. Whatever ill feelings the two men harbored stayed private. Not anymore.

Mr. Catsimatidis said he spoke with Mr. Bloomberg last fall, before the former mayor launched his bid, and he recalled Mr. Bloomberg clearly felt he was more qualified to be president. “He considers himself so much smarter than Trump and so much richer than Trump,” he said. “And Trump is sitting in his chair. Bloomberg hates him.”

The prospect of a November election showdown between Mr. Trump and Mr. Bloomberg may be hard to predict, but the two men are trading punches like crosstown rivals.

Mr. Bloomberg is “a loser who has money but can’t debate and has zero presence,” Mr. Trump tweeted. He mocks the ex-mayor’s height, calling him Mini Mike. Mr. Bloomberg tweeted that some of their mutual acquaintances in New York “laugh at you & call you a carnival barking clown.”

The billionaires’ bout ignited nearly four years ago, when Mr. Bloomberg took the stage at the Democratic National Convention. Mr. Trump, then the GOP presidential nominee, “wants to run the nation like he’s running his business. God help us,” Mr. Bloomberg said. “I’m a New Yorker, and I know a con when I see one.”

Trump campaign spokesman Tim Murtaugh said in a statement: “Mike Bloomberg is not equipped to run this country, and President Trump has made his thoughts on that clear.”

Mr. Bloomberg declined a request to be interviewed for this article. His spokesman, Stu Loeser said, “Running a golf course is about the only thing” Mr. Bloomberg would hire Mr. Trump to do.

Mr. Bloomberg, as mayor, and Mr. Trump, as a developer, occasionally crossed paths. They were never close, people familiar with their relationship said, yet they largely presented—at least publicly—a warm front.

Mr. Trump said in 2007 that Mr. Bloomberg would “go down as one of the great mayors, if not the greatest” in New York history. Mr. Bloomberg referred to Mr. Trump in 2011 as a “New York icon.” Both called each other a friend.

Messrs. Trump and Bloomberg were photographed together on the golf course. Mr. Bloomberg twice appeared on “The Apprentice,” Mr. Trump’s reality TV show. Mr. Trump was picked by the city to run a public golf course.

Given their personal differences, the cordiality rested on shaky ground. Mr. Bloomberg had little to gain from tangling with a high-profile TV personality. Likewise, Mr. Trump had little reason to antagonize the mayor, given the city’s broad land-use authority.

When Mr. Bloomberg was elected in 2002, Mr. Trump’s status as a New York real-estate developer was on the wane. After running into financial trouble in the 1990s, he would eventually shift to mostly licensing his name to developers around the globe. Yet, he still had ambitions to develop in New York.

His dealings with the Bloomberg administration hit an early setback. City Hall officials rejected Mr. Trump’s attempt to acquire 2 Columbus Circle, a property near Central Park in one of Manhattan’s landmark intersections.

The city instead sold it to what is now called the Museum of Arts and Design. Dan Doctoroff, Mr. Bloomberg’s deputy mayor for economic development, said he didn’t hear from Mr. Trump again until the “The Apprentice” made its 2004 TV debut 18 months later.

“The next morning, I got a call from him out of the blue simply to tell me the ratings of ‘The Apprentice,’ which he then proceeded to do for the next three weeks in a row,” Mr. Doctoroff said. “In the development world that we were living in, that sort of post-9/11 period, we didn’t have that much engagement with him.”

During Mr. Bloomberg’s third term, Mr. Trump explored taking over Tavern on the Green, a restaurant in Central Park. He got a chilly response from City Hall. Then came Mr. Trump’s shot at a golf course development in the Bronx.

Adrian Benepe, commissioner of the parks and recreation department for most of Mr. Bloomberg’s tenure, said the city had promised decades earlier to turn the Ferry Point landfill into a public golf course.

The city tried without success to find a developer willing to handle the conversion, which required extensive and costly environmental remediation.

The city ended up building the course with taxpayer money, Mr. Benepe said. He praised Mr. Trump’s operation of the Trump Golf Links at Ferry Point. But he was surprised to hear the Trump campaign in 2016 portray Mr. Trump’s role as a single-handed rescue after years of municipal fumbling.

“It’s a pants-on-fire lie,” Mr. Benepe said. “It was kind of a big telling moment that Trump would make up a completely fabricated story that was instantly and easily disprovable.”

A spokeswoman for the Trump Organization said, “For over 30 years, before President Trump and the Trump Organization stepped in, Ferry Point was a stalled city project, in desperate need of rescue.”

R. Couri Hay, a publicist and New York society maven, said Mr. Bloomberg is a frequent guest at charity events and gala dinners in Manhattan and the Hamptons. “Mayor Bloomberg likes to go out and about,” Mr. Hay said. “He’s no stranger to putting on black tie, although, often, his is red.”

Mr. Trump “famously doesn’t go to a lot of parties,” Mr. Hay said. “He’s more of a homebody.”

That wasn’t always the case, said Jean Shafiroff, a Manhattan philanthropist. In the late 1980s, Mr. Trump and Ivana Trump, his wife at the time, “were very big on the social scene and in philanthropy. They were at the New York City Ballet gala, pretty much everywhere.”

Mr. Bloomberg topped the Chronicle of Philanthropy’s annual ranking of the top 50 biggest donors in the U.S. His charitable contributions totaled $3.3 billion in the past year. Mr. Trump hasn’t made the list in its 20 years.

Mr. Bloomberg gets credit from many in New York’s real-estate industry for helping rebuild lower Manhattan after the Sept. 11 terrorist attacks. Mr. Trump was more of an outsider, with few close friendships among real-estate developers. As mayor, Mr. Bloomberg would attend the Real Estate Board of New York’s annual banquet. Mr. Trump was never a member of the powerful trade group, a spokesman said.

With no access to either man’s unredacted tax records, evaluating wealth is an educated guess. Forbes estimated Mr. Trump’s net worth at about $3 billion and Mr. Bloomberg’s at around $60 billion.

Mr. Bloomberg, a lifelong Democrat, switched to the Republican Party before his first race for mayor in 2001. He left the GOP in 2007 as he flirted with a 2008 presidential bid. When asked on CNN about Mr. Bloomberg’s prospects at the time, Mr. Trump said Mr. Bloomberg would be a formidable candidate because he could “spend the money that it takes to get elected.”

Mr. Bloomberg decided not to run. He instead sought permission from the City Council to bust a law prohibiting him from serving more than two terms. Mr. Trump joined a chorus supporting Mr. Bloomberg’s bid for a third term.

“I think in New York City real estate, developers are forced into a position where they try to be accommodative to the politicians,” said Stephen Meister, an attorney who has represented Mr. Trump and known him since the 1980s.

Messrs. Trump and Bloomberg took opposite sides of a national debate in 2010, but the dispute contained none of the vitriol now being volleyed between them. That summer, Mr. Bloomberg stood on Governors Island, the Statue of Liberty behind him, to deliver a speech supporting a proposal to build a mosque and Islamic community center two blocks from where terrorists had toppled the World Trade Center.

Opposition grew, drawing in Mr. Trump. He offered to buy out one of the investors in the property on the condition no mosque be built within five blocks of ground zero. Mr. Trump said the proposed location wasn’t appropriate.

Real-estate developer Sharif El-Gamal, one of the investors in the property, said he was surprised by Mr. Trump’s offer.

“Even though he was polarizing against the project, what stood out for me is that he is a rational genius in a way,” Mr. El-Gamal said. “He is somebody that understands how to push buttons and is the greatest showman that I think we’ve ever seen.”

After Mr. Trump’s offer was rebuffed, he appeared on CNN to criticize the proposal but not Mr. Bloomberg. “He’s a great mayor and he’s a great friend of mine,” Mr. Trump said in the TV interview. “He feels very strongly about freedom of religion, and I understand that.”

In 2016, Mr. Bloomberg, who at that point had been unaffiliated with any political party for nearly a decade, briefly considered running for president as an independent. Mr. Bloomberg’s younger daughter, Georgina Bloomberg, told W Magazine, after her father decided against the idea, that she was happy to have avoided campaign mudslinging with the Trumps.

“Donald Trump and his family have always been very close,” she told the magazine. “I’m good friends with his kids. I was not looking forward to having to watch our fathers go against each other.”

Ms. Bloomberg and Ivanka Trump, Mr. Trump’s oldest daughter, both appeared in the 2003 documentary “Born Rich.”

Mr. Bloomberg rejoined the Democratic Party in 2018, and he launched his bid for the Democratic nomination last fall.

In October, Georgina Bloomberg and Eric Trump’s wife, Lara Trump, were co-chairwomen of the Rescue Dogs Rock NYC charity gala. They planned to headline a charity event for rescue dogs at Mar-a-Lago in March. The Palm Beach Post reported neither would attend because of scheduling conflicts.

After Mr. Bloomberg’s first televised debate this month, largely panned, Mr. Trump lashed out at the former mayor.

“Mini Mike Bloomberg’s debate performance tonight was perhaps the worst in the history of debates, and there have been some really bad ones. He was stumbling, bumbling and grossly incompetent,” Mr. Trump wrote on Twitter. “If this doesn’t knock him out of the race, nothing will.”

Should Mr. Bloomberg face Mr. Trump in the general election, it will only get more heated, said New York public-relations executive Howard Rubenstein: “There’s some kind of war that will take place.”

Write to Michael Howard Saul at michael.saul@wsj.com and Konrad Putzier at konrad.putzier@wsj.com