WASHINGTON — Iran threatened on Monday to accelerate its nuclear program in violation of a 2015 nuclear agreement, moving it closer to the ability to build an atomic weapon — something that President Trump has vowed to prevent.

But it was Mr. Trump who withdrew the United States from the Obama-era nuclear agreement in May 2018, saying the deal wasn’t tough enough. Since then the administration has steadily imposed ever harsher sanctions on Iran as the country’s economy has sharply declined.

Until recently, Iran has held up its side of the bargain, which is still in force with five other countries: freezing much of its nuclear activity in return for relief from harsh economic sanctions. But last month, Iran’s president announced that Tehran would edge away from the restrictions. On Monday he said that by the end of this month, the country would have stockpiled more nuclear fuel than the deal allowed. Iran also suggested it might start enriching that fuel to levels higher than what is needed for nuclear power plants — its stated purpose for the nuclear program.