Leaders of Russia and Ukraine have reached a deal in their gas dispute which should allow supplies to be resumed to Europe.