The presidents of Russia and Turkey said they reached agreements on a cease-fire to take effect at midnight Thursday in northwestern Syria, where escalating fighting had threatened to put forces from the two countries into a direct military conflict.