Kenya and Somalia agreed to restore ties on Thursday after a months-long spat over oil rights that led the neighbors to halt the issuance of visas on arrival for each other’s citizens.