Trimethylglycine (TMG) is a molecule which, structurally, is the amino acid Glycine with three methyl groups attached to it. It is known as a 'betaine' molecule (a category of molecules), but because it was the first dietary betaine discovered (from Beet Root) and it is the most popular molecule referred to as a betaine, the terms ‘trimethylglycine’ and ‘betaine’ are used interchangeably.
Betaine functions very closely with choline, folic acid, vitamin B12 and a form of the amino acid methionine known as S-adenosylmethionine (SAMe). All of these compounds function as "methyl donors." They carry and donate methyl molecules to facilitate necessary chemical processes.
The donation of methyl groups by betaine is very important to proper liver function, cellular replication, and detoxification reactions. Betaine also plays a role in the manufacture of carnitine and serves to protect the kidneys from damage.
Betaine is closely related to choline. The difference is that choline (tetramethylglycine) has four methyl groups attached to it. When choline donates one of these groups to another molecule, it becomes betaine (trimethylglycine). If betaine donates one of its methyl groups, then it becomes dimethylglycine.
The main mechanisms of betaine are either its usage as a methyl donor, where it either directly donates a methyl group to reduce homocysteine into L-methionine (seen as cardioprotective) or it increases bodily levels of S-Adenosyl Methionine (SAMe) or active folate molecules, and those two can then go on to donate methyl groups to other parts of the body. Due to this, supplementation of betaine is able to indirectly support whole-body methylation, and directly support a reduction in homocysteine (which is reliably observed following moderate to high dose supplementation). A study using large doses of betaine demonstrated its ability to lower homocysteine levels in humans. (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3610948/)
The other major mechanism is that betaine is as an osmolyte, or a molecule that is shuttled in and out of a cell to affect its hydration status. Similar to Creatine, increased intracellular concentrations of betaine promote cell hydration and resilience to stressors.