A tense standoff aboard the International Space Station escalated into a near-evacuation before NASA and Russia reached a late-stage agreement over a damaged module.