The status of the British overseas territory of Gibraltar, a small isthmus on Spain’s southern coast, after Britain leaves the European Union has been agreed with Britain, Spain’s prime minister said on Thursday.