The mullahs almost screwed it up by repeatedly pulling Obama's pants down in public. They made him squirm because they knew he is weak, that he wants this deal more than they do (they don't really need it, they will ignore it anyway), and it makes them look good to make him squirm. A president with any dignity would have walked away rather than endure their insultingly aggressive behavior.
But Obama wanted this so badly he took the slaps in the face, and in return he conceded the following: no more sanctions, legitimization of the regime in Tehran by the US, and they still get to work towards a bomb. And the propaganda win of looking like they defeated us at the negotiating table. And we get.... nothing.