NEW YORK (AP) — The NFL and the referees’ union reached a tentative contract agreement at midnight Thursday, ending an impasse that began in June when the league locked out the officials and used replacements instead.

“Our officials will be back on the field starting tomorrow night” for the Cleveland-Baltimore game, Commissioner Roger Goodell said. “We appreciate the commitment of the NFLRA in working through the issues to reach this important agreement.”

With Goodell at the table, the sides concluded two days of talks with the announcement of a tentative 8-year deal, which must be ratified by 51 percent of the union’s 121 members. They plan to vote Friday.

“Our Board of Directors has unanimously approved taking this proposed CBA to the membership for a ratification vote,” said Scott Green, president of the NFLRA. “We are glad to be getting back on the field for this week’s games.”

The replacements worked the first three weeks of games, triggering a wave of frustration that threatened to disrupt the rest of the season. After a missed call cost the Green Bay Packers a win on a chaotic final play at Seattle on Monday night, the two sides really got serious.

The union was seeking improved salaries, retirement benefits and other logistical issues for the part-time officials. The NFL has proposed a pension freeze and a higher 401(k) match, and it wants to hire 21 more officials to improve the quality of officiating. The union has fought that, fearing it could lead to a loss of jobs for some of the current officials, as well as a reduction in overall compensation.

The NFL claimed its offers have included annual pay increases that could earn an experienced official more than $200,000 annually by 2018. The NFLRA has disputed the value of the proposal, insisting it means an overall reduction in compensation.

Replacement refs aren’t new to the NFL. They worked the first week of games in 2001 before a deal was reached. But those officials came from the highest level of college football; the current replacements do not. Their ability to call fast-moving NFL games drew mounting criticism through Week 3, climaxing last weekend, when ESPN analyst Jon Gruden called their work “tragic and comical.”

Those comments came during “Monday Night Football,” with Seattle beating Green Bay 14-12 on a desperation pass into the end zone on the final play. Packers safety M.D. Jennings had both hands on the ball in the end zone, and when he fell to the ground in a scrum, both Jennings and Seahawks receiver Golden Tate had their arms on the ball.

The closest official to the play, at the back of the end zone, signaled for the clock to stop, while another official at the sideline ran in and then signaled touchdown.

The NFL said in a statement Tuesday that the touchdown pass should not have been overturned — but acknowledged Tate should have been called for offensive pass interference before the catch. The league also said there was no indisputable evidence to reverse the call made on the field.

That drew even louder howls of outrage. Some coaches, including Miami’s Joe Philbin and Cincinnati’s Marvin Lewis, tried to restore some calm by instructing players not to speak publicly on the issue.

Fines against two coaches for incidents involving the replacements were handed out Wednesday.

New England Patriots coach Bill Belichick was docked $50,000 for trying to grab an official’s arm Sunday to ask for an explanation of a call after his team lost at Baltimore. And Washington offensive coordinator Kyle Shanahan was tagged for $25,000 for what the league called “abuse of officials” in the Redskins’ loss to Cincinnati on Sunday. Two other coaches, Denver’s John Fox and assistant Jack Del Rio, were fined Monday for incidents involving the replacements the previous week.

“I accept the discipline and I apologize for the incident,” Belichick said.

Players were in no mood for apologies from anyone.

“I’ll probably get in trouble for this, but you have to have competent people,” Carolina receiver Steve Smith said. “And if you’re incompetent, get them out of there.”

Added Rams quarterback Sam Bradford: “I just don’t think it’s fair to the fans, I don’t think it’s fair to us as players to go out there and have to deal with that week in and week out. I really hope that they’re as close as they say they are.”

They were. Finally.