Pakistan is a key Western ally and has helped the United States and Britain thwart terrorist attacks .