Britain has agreed to pay hefty settlements to former Guantanamo Bay detainees who sued the government for alleged complicity in their torture — one of the first big payouts stemming from the U.S.-led war on terror.

After months of legal wrangling, Britain’s spy agencies chose to settle the lawsuit to avoid a series of pricey and prolonged court cases in which open testimony from secret agents could have jeopardized national security.