The chemical reactions and pathways involving phosphonates, any organic compounds containing one or more C-PO(OH)2 or C-PO(OR)2 (with R=alkyl, aryl) groups. Metabolism of phosphonic acid itself, an inorganic compound without the biochemically relevant C-P bond, is not included.