The chemical reactions and pathways involving allantoin, (2,5-dioxo-4-imidazolidinyl)urea, an intermediate or end product of purine catabolism.