Hopes for a final agreement in the Iran nuclear talks grew early Tuesday as the United States and its five negotiating partners gathered shortly after midnight for an hour-long meeting after a day of alternating expectation and pessimism.

Shortly before that session, Secretary of State John F. Kerry met late Monday with Russian Foreign Minister Sergei Lavrov and Federica Mogherini, the foreign policy chief of the European Union. The pace of the meetings raised the possibility that an agreement might be reached in the middle of the night.

In a reflection of the roller coaster that has characterized the negotiations in recent days, diplomats had been optimistic Monday morning that a final agreement would be reached before midnight Monday. But just before nightfall, Iranian Foreign Minister Mohammad Javad Zarif, making one of his periodic appearances on the third-floor balcony of the Coburg Palace hotel where the talks are being held, dashed those hopes, saying Monday would not be the day. He characterized the mood in the closed-door talks as “sleepy, overworked.”

At midday Monday, White House spokesman Josh Earnest said that the talks would be extended again if the negotiators thought more time would result in an agreement. He said the U.S. negotiating team would remain in Vienna. Kerry warned last week that the talks were not “open ended” and that the United States was prepared to walk away from them.

“What started out as rather a long list of differences has slowly . . . but steadily narrowed,” Earnest said at a White House news briefing. “That’s an indication that we are making progress toward an agreement.”

“What’s also true is that typically some of the most difficult issues are the ones that get kicked to the end,” he added. “That’s why the president is going to resist any effort to sort of fast-forward toward the closing.”

It was an abrupt turnaround on a day when many expected that more than a year and a half of negotiations would finally bear fruit, with Iran accepting restrictions on its nuclear program in return for the lifting of economic sanctions.

President Hassan Rouhani even tweeted a premature congratulatory note, saying “#IranDeal is the victory of diplomacy & mutual respect over the outdated paradigm of exclusion & coercion. And this is a good beginning.”

That tweet was quickly deleted, only to be reposted a short time later with a qualifier and a change of tense: adding the word “If” at the beginning, and saying “This will be a good beginning.”

Part of the delay is the result of making sure the draft agreement, which is nearly 100 pages with its annexes, says the same thing in Persian that it does in English to minimize misunderstandings later on, and getting approval from leaders in the seven capitals.

But the talks also are snagged on a handful of substantive issues, including how quickly sanctions would be lifted, when frozen Iranian assets would be released and how much access Tehran would grant investigators looking into whether it tried to build nuclear weapons. But perhaps the biggest sticking point revolves around a U.N. embargo on conventional weapons and ballistic missiles.

The embargo is part of U.N. Security Council resolutions that impose sanctions on Iran for resisting questions about its nuclear program. It was placed there in an effort to push Iran to negotiate.

Under a framework agreement reached in April, all U.N. nuclear-related resolutions will be lifted after international inspectors verify that Iran’s nuclear program is for non-military purposes, such as energy production and medical isotopes. The deal also says a new umbrella resolution would incorporate “important restrictions on conventional arms and ballistic missiles.”

The United States and its European partners say the arms embargo should remain in place, at least for now, because they fear that an Iran flush with cash from a deal would use the money to support proxy groups elsewhere in the Middle East. Iran, backed by China and Russia, argues that it should be lifted entirely, because it is part of a nuclear resolution that a deal would render moot.

William Branigin in Washington contributed to this report.