Two centuries ago, in the fall of 1818, the Saudi monarch was brought to Istanbul in chains. He was displayed in a cage to the cheering crowds outside the Hagia Sophia mosque, and then, amid celebratory fireworks, his head was chopped off.

This gruesome episode in the shared history of Turkey and Saudi Arabia hasn’t been mentioned in public as the two countries have clashed over the Oct. 2 killing of the Saudi journalist Jamal Khashoggi in the kingdom’s consulate in Istanbul. But the long legacy of rivalry between the two...