The agreement paves the way for a Brexit deal to be finalised at an EU summit at the weekend.