The epic battle over Market Basket that sparked an extraordinary worker revolt and captivated the public through the summer ended Wednesday when Arthur T. Demoulas reached a deal to buy the company from rival relatives for more than $1.5 billion.

Market Basket’s shareholders announced the deal at 11:15 p.m. after several days of suspenseful negotiations. Arthur T. Demoulas and his sisters will buy the shares of their cousin Arthur S. Demoulas and other relatives on his side of the family, who collectively own 50.5 percent of the company.

“Effective immediately, Arthur T. Demoulas is returning to Market Basket with day-to-day operational authority of the company,” the statement said. “All associates are welcome back to work with the former management team to restore the company back to normal operations.”

Get Talking Points in your inbox:

An afternoon recap of the day’s most important business news, delivered weekdays.

The sale agreement, which will take months to formally close, ends a fight so bitter it took the intervention of the governors of Massachusetts and New Hampshire to help the Demoulas family resolve it after nearly a quarter-century.

The agreement authorizes Arthur T. to manage the business and stabilize operations at its 71 stores, where employee walkouts and customer boycotts had brought business to a virtual standstill for six weeks. He will also be able to rehire several managers who were fired along with him. However, until the deal closes, he will continue to work with the chief executives hired to replace him, Felicia Thornton and James Gooch.

As word of the deal spread, employees of the company reacted with elation. Many walked off the job after Arthur T. was fired in June by a board of directors controlled by Arthur S. The employee protest crippled the company’s operations — giving Arthur T. leverage in the fight — but it also left many workers without income for more than a month.

“I’m elated. I’m elated. That is awesome,” said Andy Lien, a director of the chain’s perishable warehouse in Andover who led workers who walked off the job in July.

Wendy Maeda/Globe Staff/File 2013

A deal to sell Market Basket to Arthur T. Demoulas has been signed, a source said.

Advertisement

“It’s just fantastic,” said Ann Rogers, 55, a protesting employee who worked in the company’s accounts payable department. “I’ve been working with this company for 28 years, and this has been hanging over the company’s head the whole time. This fight was absolutely worth it.”

The statement issued by the shareholders thanked customers for their patience through the ownership feud and employee protests that left store shelves stripped bare of fresh food and cost the company millions of dollars a day. “Our shared goal is to return Market Basket to the supermarket that its customers have come to rely on for service, quality and best prices,” they said.

However, it will take several days, if not weeks, to return the stores to normal operations. The company’s buyers and managers must reestablish contact with vendors that had at least temporarily cut ties with Market Basket. It also might be difficult to get back some customers who have left because of distaste for family drama or because they have come to appreciate the offerings of other supermarkets.

David Livingston, a supermarket industry analyst at DJL Research in Milwaukee, predicted 80 to 90 percent of customers will return.

But he cautioned shoppers to prepare for a slightly different atmosphere, with the possibility of lingering tensions and uncertainty about whether a company suddenly saddled with large debt obligations can keep prices so low.

Advertisement

“I just don’t think Market Basket will ever be quite the same,” Livingston said. “It’s like going through a divorce and getting a second family.”

The sale came together Wednesday after several days of fits and starts. Last Friday, Governor Deval Patrick and Governor Maggie Hassan of New Hampshire predicted a deal by the end of the weekend. But a final agreement proved to be much more elusive, with the parties remaining deadlocked through most of the last few days.

At one point, the board considered a plan to close all but 10 of the company’s stores and lay off most employees. The governors expressed relief that such drastic steps were ultimately avoided.

“Market Basket is a major employer in Massachusetts and New Hampshire, and an important local resource for the communities the company serves,” the governors said. “We are delighted that the parties have reached agreement . . . so that employees can return to work and customers will once again be able to rely on these stores to meet their needs.”

The company employs 25,000 people in Massachusetts, New Hampshire, and Maine. It is also the main draw in many shopping centers in the region as well as a key source of business for farmers, specialty food makers, and other suppliers.

Over the last three days, the company’s board scheduled multiple meetings to take up the sale agreement but repeatedly canceled them upon learning shareholders could not reach an accord. Neither side issued any formal statements until the deal was finally signed late Wednesday.

Arthur T. made a final offer late last week that removed a key stumbling block by including about $550 million in financing from an unidentified private equity firm. The money replaced seller financing that would have required Arthur S. and his relatives to lend money to Arthur T.’s side to help complete the deal.

The rest of the money for the purchase will come from a cash payment by Arthur T. and his sisters, and a mortgage loan secured by the company’s real estate holdings in Massachusetts, New Hampshire, and Maine.

Both sides will benefit from Wednesday’s agreement. Arthur S., his sisters, and sister-in-law Rafaela Evans will get more than $1.5 billion for their shares in the business. Arthur T. and his sisters, meanwhile, will get full ownership of the company and can begin to get it back in working order.

Furthermore, if the agreement holds, all members of the fractured Demoulas family will settle a fight that has divided the family for more than 24 years. Their battle started in the early 1990s when Arthur S. and his relatives filed a lawsuit accusing Arthur T.’s father, Telemachus “Mike” Demoulas, of stealing their shares in the company.

Arthur S. and his immediate relatives won that case, getting a $500 million judgment that left them with a slight majority ownership of the company. Arthur T. and his siblings retained a 49.5 percent stake, and the two sides have continued to fight about the management of the multibillion-dollar company in recent years.

During that time, board meetings constantly dissolved into expletive-laced shouting matches, as Arthur T. and board members disagreed about spending on real estate transactions, employee bonuses, and other matters. The battle reached a boiling point with Arthur T.’s firing in late June.

While the family has finally proved it could rise above infighting, business specialists said the company’s employees accomplished a rare feat in halting operations until they got what they wanted.

“To have an internal uprising of just about everyone, without a union, is very unusual in American industry,” said David Lewin, professor of management at the University of California, Los Angeles. “And it’s even more unusual for workers to say, ‘We want this guy to come back’ — and to have him actually come back.”

Still, he cautioned against self-congratulations, especially given the grinding work and financial distress Arthur T. and employees will face in coming weeks. “If it turns out he’s overpaid for the company, those chickens could come home to roost pretty quickly,” Lewin said.