The MTA and the unions representing 5,400 Long Island Rail Road workers, assisted by Gov. Andrew M. Cuomo, reached a tentative deal Thursday to avert a crippling LIRR strike that would have begun Sunday.

"This is a compromise by both parties after four long years," Cuomo said.

The contract calls for "fair compensation for valued employees," while ensuring "fares don't go up and the MTA has funds for repairs and to manage the system," the governor said.

Under the deal, LIRR workers will get 17 percent raises over 6 1/2 years and "all employees will for the first time contribute to their health insurance costs, and new employees will have different wage progressions and pension plan contributions," according to the governor's office.

The unions, following the recommendations of two federal mediation boards, had called for 17 percent raises over six years.

Metropolitan Transportation Authority chairman Thomas Prendergast and lead LIRR union negotiator Anthony Simon agreed that the contract was fair and reasonable.

Prendergast said the contract is structured "in a way that protects the commuter as well as the long-term fiscal stability of the MTA."

Simon praised the governor for getting involved in the negotiations.

"This was about the riders," Simon said. "We cared about the riding public," and the financial stability of the railroad and the members of the eight LIRR unions.

Those members will vote to ratify the contract by Aug. 15, and the MTA board votes on it in September.

The Long Island Rail Road Commuter Council said it appreciated Cuomo's role in helping broker a deal.

"All riders feel relief at the announcement of this settlement," council chair Mark Epstein said in a statement. "We are encouraged by Governor Cuomo's assurances on fares and the MTA's ability to fund its Capital Program and look forward to reviewing additional details on the settlement and the way in which it will be funded."

State Sen. Jack Martins (R-Mineola), who had asked Cuomo to intervene in the negotiations, also praised the governor for "his efforts to bring all sides together to reach an agreement."

"Importantly, all sides have promised that this contract will not increase fares for already overburdened LIRR riders," Martins said.

Earlier Thursday, Simon said he was confident a resolution would be reached to avert a strike, after Cuomo had taken a lead role in ongoing negotiations.

Cuomo on Thursday morning summoned the unions and the MTA to his Manhattan offices, saying he wanted "to make sure I have done everything to avoid a strike."

Earlier Thursday, Simon said he was on the phone with Cuomo from 6 p.m. Wednesday "through the night."

"Him and I discussed this late into the evening and late into the wee hours," Simon said.

Cuomo was at the table Thursday for the second day of resumed negotiations, his office said.

"Late yesterday, when the conversations had not been fruitful, I began participating in them directly," Cuomo said in a statement. Emphasizing that "time is very short," Cuomo said he convened Thursday's meeting "to continue discussions" less than three days before the planned strike.

Reps. Steve Israel (D-Huntington), Peter King (R-Seaford) and Tim Bishop (D-Southampton) issued a statement Thursday applauding news of the deal.

"Governor Cuomo deserves credit for finalizing an agreement that will avoid a strike, and we have worked with him and both parties over the past months to help facilitate this outcome," the statement said. "When negotiations collapsed, and both sides turned to Washington, we made it clear that the ultimate solution rested at the bargaining table. Since then, we have worked on a bipartisan basis with the governor and both parties to keep negotiations going, and today's outcome is exactly what we envisioned."

The swift and apparent end to the four-year contract saga between the MTA and the eight LIRR unions was a far cry from last November, when MTA management announced its intention to reduce a planned 2015 fare increase for the railroad's 145,000 daily riders to 4 percent from the originally planned 7.5 percent. But the reduction would only be done if unions agreed to a three-year freeze on labor costs, in which any raises would be paid for through other union concessions.

LIRR unions rejected that proposal and two Presidential Emergency Boards appointed by President Barack Obama eventually sided with the unions, calling labor leaders' offer of a 17 percent, six-year pact a "reasonable" solution. The contract covered about 5,400 railway employees, who had been without a pact since June 2010, and sought no changes in work rules, health care payments and pensions for future workers.

During months of negotiations marked by acrimony on both sides, Cuomo said he would not intervene in the dispute. Members of Long Island's congressional delegation also said lawmakers would not step into the fray, insisting that both sides work until they reached a deal that would spare commuters and Long Island's recovering economy a crippling strike.

In its talks with LIRR unions over more than six months, the MTA shifted its stance several times.

First, agency officials offered LIRR unions 3 percent raises, then 11 percent raises, modeled after an agreement with subway and bus workers for 8 percent raises over five years. Then the MTA offered unions 17 percent raises over seven years -- not the six recommended by the two White House-appointed boards.

Among other things, the offer called for workers for the first time to contribute to their health care, a provision that rankled union leaders who accused the MTA of failing to bargain in good faith and not following the nonbinding recommendations of the two presidential boards.

After contract talks broke down Monday, the LIRR unions and the MTA prepared for a strike that would have started at 12:01 a.m. Sunday.

In a marked change of tone from earlier this week, when both sides sent dueling messages making their cases, LIRR union leaders and representatives for the MTA held a lengthy negotiation session Wednesday.

Those talks came after Cuomo called for the two sides to return to the table.

In a historical coincidence, Cuomo's father, Gov. Mario Cuomo, ended the last major LIRR strike in 1994 by forcing the MTA to capitulate to the unions.

The developments came as the White House weighed in on the labor dispute affecting the nation's largest commuter railroad. Nearing the end of the federal process designed to avoid work stoppages, White House spokesman Keith Maley said Obama's administration hoped "both sides will be able to resolve this issue quickly in a way that is fair for workers, fair for the state of New York, and fair for residents in and around Long Island."