TEWKSBURY, Mass. — The protracted negotiations between the rival factions of the Market Basket supermarket chain came to a close Wednesday night with the completion of a deal to sell the company to former CEO Arthur T. Demoulas.

Market Basket said in a statement late Wednesday that Demoulas would return to the company and that he and his management team would handle day-to-day operations while the purchase is completed.

The company’s two current CEOs, Felicia Thornton and Jim Gooch, are to remain in their positions until the deal is closed, the statement said. The closing is expected in the “next several months.”

Demoulas’ offer to buy out the 50.5 percent of the company controlled by his cousin, Arthur S. Demoulas, is worth about $1.5 billion, according to the Boston Globe.

The employee website mydemoulas.net posted a statement Wednesday night announcing that an agreement had been reached.

“Effective immediately, Arthur T. Demoulas is returning to Market Basket with day-to-day operational authority of the company,” the website said.

The two sides of the family have been feuding for years.

The sale could still take months to close, according to the Globe, and follows a standoff so bitter that the governors of Massachusetts and New Hampshire intervened.

Last week, Deval Patrick and Maggie Hassan predicted that the deal would be signed over the weekend, but after a series of postponed board meetings, nothing happened until Wednesday night.

The deal reportedly gives Arthur T. full authority to manage the 71-store operation, including a location in Biddeford. The chain employs 25,000 full- and part-time workers.

It also reported that Arthur T. and his management team will return during the interim period while the transaction to purchase the company is completed. The current CEOs will remain in place pending the closing, which is expected to occur in the “next several months.”

The website says that all associates are welcome back to work.

Justine Griffin, a spokeswoman for Arthur T. Demoulas, could not be reached Wednesday.

The late-night deal follows several weeks of employee firings and protests by thousands of workers, who called for the board of directors to reinstate Demoulas. They also asked customers to boycott the stores, which analysts said was costing the company millions of dollars in revenue each day.

About 200 distribution and administrative workers walked off their jobs in mid-July. The walkout was a reaction to the board’s ouster of Demoulas.

The job action left shelves at many Market Basket grocery stores empty. Thousands of part-time workers were taken off the schedule indefinitely as a result, including about 270 workers at the Biddeford store.

Demoulas is a hero to many employees. Stories of his generosity, sincerity and compassion are well known within company circles.

But in court documents, Arthur S. has alleged that Arthur T. abused his authority as CEO to pursue a rapid expansion strategy that the majority of board members did not support.