Gibraltar released an Iranian tanker that the British overseas territory impounded in July, opening the way for Tehran to free a British-flagged vessel it subsequently seized and help ease tensions in the Persian Gulf.

The decision came after a last-minute U.S. request to seize the tanker itself, a Gibraltar government spokesman said, prompting the court to delay its ruling on the vessel’s detention by several hours. Gibraltar’s government said authorities would separately consider the U.S. request.

The...