Obama told reporters at the White House that he had a constructive conversation with the Iranian leader.
"While there will surely be important obstacles to moving forward and success is by no means guaranteed, I believe we can reach a comprehensive solution," he said.
Obama said he and Rouhani have directed their teams to work quickly to pursue an agreement. He said the U.S. will coordinate closely with its allies - including Israel, which considers an Iranian nuclear weapon capability to be an existential threat.
The fact that it had been so long since American and Iranian presidents had traded words reflected the "deep mistrust between our countries," Obama said. But he added that it also indicated the opportunity for moving forward.
"I do believe there is a basis for a resolution," he said.
The conversation came hours after Rouhani, wrapping up a trip to the U.S., called the United States a "great" nation, a sharp reversal from his predecessors that buoyed hopes that the two governments can stop the escalation of tensions.
"I want it to be the case that this trip will be a first step, and a beginning for better and constructive relations with countries of the world as well as a first step for a better relationship between the two great nations of Iran and the United States of America," Rouhani told a news conference at a hotel near U.N. headquarters.
Rouhani has pledged to reduce nuclear tensions, and U.N. officials said they have seen encouraging signs from Tehran. Iranian and U.N. officials agreed to meet again Oct. 28 to continue talks on how to investigate suspicions that Iran worked secretly on trying to develop nuclear weapons. Tehran denies that it wants to build a weapon.