Diplomats have agreed a four-month extension to the deadline for an agreement between Tehran and world powers on Iran's nuclear programme.