Oil ends year of wild price swings with second straight annual gain