U.S. President Barack Obama hailed a step towards a "more hopeful world" and Iran's President Hassan Rouhani said it proved that "constructive engagement works". But Israel pledged to do what it could to halt what it called an "historic surrender".
The agreement will now be debated in the U.S. Congress, but Obama said he would veto any measure to block it.
"This deal offers an opportunity to move in a new direction," Obama said. "We should seize it."
Under the deal, sanctions imposed by the United States, European Union and United Nations will be lifted in return for Iran agreeing long-term curbs on a nuclear program that the West has suspected was aimed at creating a nuclear bomb.
Iran will mothball for at least a decade the majority of its centrifuges used to enrich uranium and sharply reduce its low-enriched uranium stockpile.
The agreement is a political triumph for both Obama, who has long promised to reach out to historic enemies, and Rouhani, a pragmatist elected two years ago on a vow to reduce the isolation of his nation of 80 million people.
Both face scepticism from powerful hardliners at home in nations that referred to each other as "the Great Satan" and a member of the "Axis of Evil".
"Today is the end to acts of tyranny against our nation and the start of cooperation with the world," Rouhani said in a televised address. "This is a reciprocal deal. If they stick to it, we will. The Iranian nation has always observed its promises and treaties."
Delighted Iranians danced in the streets of Tehran, whole motorists sounded car horns and flashed victory signs in celebration after the announcement a deal they hope will end years of sanctions and isolation.
For Obama, the diplomacy with Iran, begun in secret more than two years ago, ranks alongside his normalization of ties with Cuba as landmarks in a legacy of reconciliation with foes that tormented his predecessors for decades.
"History shows that America must lead not just with our might but with our principles," he said in a televised address. "Today's announcement marks one more chapter in our pursuit of a safer, more helpful and more hopeful world."
Republicans lined up to denounce the deal. Presidential candidate Lindsey Graham, a senator from South Carolina, called it a terrible deal that would make matters worse. Senator Marco Rubio suggested he would re-introduce sanctions if elected to the White House next year.
The Republican-controlled Congress has 60 days to review the accord, but if it votes to reject it Obama can use his veto, which can be overridden only by two-thirds of lawmakers in both houses. That means dozens of Obama's fellow Democrats would have to rebel against one of their president's signature achievements to kill it, an unlikely prospect. Leading Democratic presidential candidate Hillary Clinton called the deal "an important step that puts the lid on Iran's nuclear programs".
The Senate was not expected to vote on the deal before September.
While the main negotiations were between the United States and Iran, the four other U.N. Security Council permanent members, Britain, China, France and Russia, are also parties to the deal, as is Germany.
Enmity between Iran and the United States has loomed over the Middle East for decades.
Iran is the predominant Shi'ite Muslim power, hostile both to Israel and to Washington's Sunni Muslim-ruled Arab friends, particularly Saudi Arabia. Allies of Riyadh and Tehran have fought decades of sectarian proxy wars in Syria, Lebanon, Iraq and Yemen.
But there are also strong reasons for Washington and Tehran to cooperate against common foes, above all Islamic State, the Sunni Muslim militant group that has seized swathes of Syria and Iraq. Washington has been bombing Islamic State from the air while Tehran aids Iraqi militias fighting it on the ground.
British Foreign Secretary Philip Hammond told reporters that the deal was about more than just the nuclear issue:
"The big prize here is that, as Iran comes out of the isolation of the last decades and is much more engaged with Western countries, Iranians hopefully begin to travel in larger numbers again, Western companies are able to invest and trade with Iran, there is an opportunity for an opening now."