'Historic' deal averts government shutdown