VIENNA—Iran reached a landmark nuclear agreement with the U.S. and five other world powers, a long-sought foreign policy goal of President Barack Obama that sets the White House on course for months of political strife with dissenters in Congress and in allied Middle Eastern nations.

The accord, which comes after a decade of diplomatic efforts that frequently appeared on the verge of collapse, aims to prevent Iran from producing nuclear weapons in exchange for relief of economic sanctions.

...