After an extended chase that included overtures on both sides and flirtations with other parties, Men’s Wearhouse and Jos. A. Bank will combine to create the nation’s fourth-largest menswear retail chain.

Men’s Wearhouse Inc. said Tuesday that it’s buying its rival Jos. A. Bank Clothiers Inc. for $1.8 billion. The company will pay $65 a share, a 5 percent premium to Jos. A. Bank’s Monday closing price of $61.83. Jos. A. Bank also said it’s terminating its deal to acquire the parent company of Eddie Bauer, which sells rugged outerwear.

On Tuesday, shares of both companies rose on the news: Men’s Wearhouse’s stock was up nearly 5 percent to $57.14, while shares of Jos. A. Bank increased nearly 4 percent to $64.22.

The acquisition comes after months of the two chains publicly fighting over who would acquire whom. Industry watchers had speculated that a merger was inevitable given the challenges the companies face in the competitive menswear landscape. With more than 1,700 U.S. stores and $3.5 billion in annual sales, the combined company’s reach in men’s clothing will fall behind only Macy’s, Kohl’s and J.C. Penney.

“Together, Men’s Wearhouse and Jos. A. Bank will have increased scale and breadth,” Doug Ewert, CEO of Men’s Wearhouse, said in a statement.

Jos. A. Bank made the first move in October when it offered to buy its larger rival for $2.3 billion. Men’s Wearhouse shot down that offer, and turned the tables, offering to buy its rival for $1.54 billion. But after Jos. A. Bank turned down that bid, Men’s Wearhouse increased its offer to $1.6 billion, and then again to $1.78 billion.

In the middle of the back-and forth, Jos. A. Bank said last month that it was buying Everest Holdings LLC, the parent company of Eddie Bauer. But the company left the door open for a deal with Men’s Wearhouse by saying if it received a superior acquisition offer, it would pay a termination fee to end the Eddie Bauer deal.

By early March, Men’s Wearhouse had an offer of $63.50 a share on the table but said it may raise the bid to $65 a share if some conditions were met. Then, a few days later, the companies announced they were exchanging certain confidential information with each other.

Despite the rough courting period, both companies say they expect a smooth integration. In a joint press release, they said shareholders of both companies will benefit from about $100 million to $150 million in savings realized over three years as the company streamlines its duplicative corporate functions and improves sourcing and merchandising.

“Our board has been rigorously focused on pursuing a path for our shareholders that maximizes value created,” said Robert N. Wildrick, chairman of Jos. A. Bank’s board. “The transaction we are announcing today clearly reflects the success of our efforts.”

A spokesman for Men’s Wearhouse declined to comment on any layoffs or management changes beyond what was in the joint press release: “Management will consist of the most qualified individuals from both organizations.”

Analysts say there’s a bright future for the combined company. The suit business, which generated $2.3 billion in revenue last year, has been relatively healthy. It’s been up 4 percent over the past three years, according to market research firm NPD Group, fueled in part by tight-fitting varieties that have attracted young males.

The companies also have complementary businesses. Men’s Wearhouse, which sells men’s sportswear and suits through its 1,200 stores at its Men’s Wearhouse, Moores and K&G chains, caters to young male customers looking for their first suit. Meanwhile, Jos. A. Banks focuses on a more established clientele that’s looking for a good deal at its 623 stores with promotions like “buy one suit or sport coat and get three free.”

Richard Jaffe, a Stifel Nicholaus analyst, said the acquisition means that both companies can lower costs, whether it’s buying shopping bags or buying TV ads. He also said each could borrow from the other’s expertise. He could see Jos. A. Bank selling tuxedos, for instance, or Men’s Wearhouse improving on its sportswear offerings.

“There are real cost savings and opportunities to turn around the business,” he said.