MADRID—The war in Iran hadn’t even begun, and Spain’s prime minister had resolved to oppose it. In the nerve center of Spain’s government, housed in a leafy compound in Madrid, aides to Prime Minister Pedro Sánchez were reading intelligence reports last December, which assessed that President Trump was charting a course for war with Iran. As they analyzed the messy consequences for Europe’s energy supplies and economy, they already knew their boss would rail against it—loudly—whatever Trump’s reaction. For the past year, most of Europe has walked on eggshells with Trump. Sánchez has been trialing an alternative tactic: the “Just…