More than 4,000 Brigham and Women’s nurses will remain on the job after reaching a tentative contract agreement with Mass General Brigham hours before an open-ended strike.