The agency was a key player in renewable energy and disaster protection around the world—until Elon Musk showed up.