Lesotho's feuding political parties have agreed to hold early elections by February, in a bid to exit a crisis that has seen a coup attempt and running battles among the security forces.