Perilously close to a government shutdown, congressional leaders reached agreement with the White House late Friday night on a deal to cut tens of billions of dollars in federal spending and avert the closure.