The chemical reactions and pathways involving a thioester, a compound of general formula RC(=O)SR' in which the linking oxygen in an ester is replaced by a sulfur atom. They are the product of esterification between a carboxylic acid and a thiol.