Unions reach a tentative deal, averting major rail strike