It was the battle of the summer, a family feud that sparked a worker revolt and pitted billionaire cousins against each other as they struggled for control of the Market Basket supermarket chain.

The contest ended late Wednesday night, when Arthur T. Demoulas reached a deal to buy the company from his relatives for more than $1.5 billion. Market Basket’s shareholders announced the deal at 11:15 p.m. after several days of roller-coaster 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.

In a statement, Market Basket asked managers, employees, and customers to return to stores to help get Market Basket running again. It also announced the reinstatement of Arthur T., who had been fired as president in June.