By Lauren Hirsch and Greg Roumeliotis

(Reuters) - The board of the charitable trust that controls Hershey Co <HSY.N> said on Friday it had reached an in-principle agreement with the Pennsylvania Attorney General's office that would avoid a legal row in exchange for reforms in how it is run.

The settlement could provide stability to the trust following months of infighting and confrontation with the attorney general's office. It could also offer the clarity needed for Mondelez International Inc <MDLZ.O> to make a new approach to acquire Hershey.

The $12 billion trust, set up by company founder Milton Hershey over a century ago to fund and run a school for underprivileged children, must approve any sale of the company. It rejected a $23 billion cash-and-stock offer for Hershey by Mondelez, the maker of Oreo and Cadbury chocolate, last month.

The Pennsylvania Attorney General's office, the trust's sole overseer, had threatened legal action to remove trustees unless a settlement over its governance was reached by the end of July.

"We have reached an agreement in principle and are working on the final details in productive discussions with the Office of the Attorney General," Kent Jarrell, a spokesman for the trust’s board, said.

"Yesterday, I met with board members and a lawyer for the Trust, along with our people, and I agreed on behalf of the Attorney General in principle to a series of changes that the Trust would implement," said First Deputy Attorney General Bruce L. Castor Jr. "When that is reduced to writing, and if it is signed by us and them, Pennsylvania Attorney General Kathleen Kane will make the terms public."

The agreement will impose 10-year term limits on trustees, according to people familiar with the matter who asked not to be identified because the settlement's details have not been announced. Three trustees - Joseph Senser, Robert Cavanaugh and James Nevels - will have to step down by the end of the year, the people said. Senser and Cavanaugh had been trustees since 2001, while Nevels has been a trustee since 2007.

Hershey Trust board Chairwoman Velma Redmond, who joined the trust in 2003, will stay on to ensure continuity, but will step down by the end of 2017, along with James Mead, a trustee since 2007, the sources added. Mead, Nevels and Cavanaugh are the trust's three representatives on Hershey's board of directors.

Caps on trustees' compensation are also part of the settlement, though these exclude salaries of trustees at Hershey and other affiliates, the people said. The Pennsylvania Attorney General's office will also be given a 30-day window to object to new trustees, the people added.

The agreement is unlikely to please many Milton Hershey School alumni that had been calling for deeper reforms, said Ric Fouad, a prominent alumnus and a board member for Protect the Hersheys' Children, an organization that calls for significant changes at the trust.

"They have squandered the ability to get reforms. A broken oversight office can't fix a broken charity," said Fouad, referring to the fact that Attorney General Kathleen Kane has had her legal license revoked and will not be seeking re-election in November.

TURMOIL

The trust has been rocked by internal dissent and turnover since it last reached a reform agreement with the attorney general's office in 2013. Trustee Joan Steel resigned earlier this month, following the departures of Richard Zilmer, John Fry and Stephanie Bell-Rose over the past year.

The trust normally has 10 board members.

Cavanaugh was the subject of an internal conflict of interest investigation stemming from his role in helping secure a summer internship for his son at one of the trust's investment management firms. Cavanaugh, appointed to the board in 2001, was the trust's chairman at the time.

This year, the trust fired its executive vice president, after he pleaded guilty to wire fraud associated with campaign contributions. It also fired its chief compliance officer, after placing him on leave, when a letter he wrote detailing the trust’s bitter feuds leaked to the public.

Stability at the trust could make it more open to reviewing its ownership of Hershey. The trust owns close to a third of Hershey, but the company accounts for more than two-thirds of its investment holdings.

In 2002, the trust cited the need for diversification as a reason of putting Hershey up for sale. Hershey then attracted a $12.5 billion offer by chewing gum maker Wm. Wrigley Jr. Co. However, the deal was abandoned after Pennsylvania's Attorney General successfully petitioned a court to block the offer amid opposition from the local community.

"This portfolio that is meant to rescue needy children is being exposed to needless risk that could be diversified away without compromising expected return." said Robert Sitkoff, a Harvard Law School professor specializing in wills, trusts, estates, and fiduciary administration.

(This version of the story was refiled to fix misspelling of Cavanaugh in eighth paragraph)

(Reporting by Lauren Hirsch and Greg Roumeliotis in New York; Additional reporting by Lisa Baertlein; Editing by Leslie Adler and Tom Brown)