NI deal struck in historic talks