Afghanistan and the United States on Tuesday signed a long-delayed security agreement that will allow some US troops to stay in the country next year, one day after the inauguration of new Afghan President Ashraf Ghani.