Rival Libyan militias agreed Monday to a truce after several days of fighting on the outskirts of Tripoli killed at least 12 people and stoked fears of a return to the violence that gripped the capital last year.