Cellular respiration consists of a chain of electron transport molecules, each of which which has an electrochemical gradient to the others. Electrons pass from molecule to molecule and energy is extracted at each step, which is used to synthesize adenosine triphosphate (ATP), which stores the energy extracted and serves as the fuel of the cell, powering its other activities. At the end of the chain, the electrons have to go somewhere and in aerobic organisms, O2 serves as the final electron acceptor. Oxygen works well in this role since it maintains a huge electrochemical gradient and lots of ATP producing steps can fit ahead of it.
But other molecules can accept electrons too, if less efficiently. In methanogens, CO2 accepts the electrons and methane is produced as a biproduct. This is one of the sources of cow-farts. In some organisms, sulfates accept the electrons and hydrogen sulfide is produced as a biproduct. This is where that rotten-egg smell of sewer gas comes from.
There are many other possibilities as well.
https://en.wikipedia.org/wiki/Anaerobic_respiration
The problem with anaerobic respiration is that it isn't as efficient as aerobic respiration and produces fewer ATP molecules.
Anaerobic organisms can either be facultative anaerobes or obligate anaerobes. Facultative anaerobes are capable of aerobic respiration in the presence of oxygen, but can switch over to some form of anaerobic respiration if oxygen is in short supply. Many prokaryotes (bacteria and archaea) are facultative anaerobes. Obligate anaerobes must respire anaerobically and can't survive in the presence of oxygen. (Oxygen is highly reactive and oxidation is very corrosive to biochemistries that aren't adapted to tolerate and exploit it.) These obligate anaerobes were probably the ancestors of all the aerobes and existed on the Earth before the Earth's atmosphere possessed large amounts of O2. They still exist today here and there, in environments where oxygen isn't found. Anaerobic respiration isn't as efficient as aerobic respiration, but there aren't any aerobic organisms in these anaerobic environments to compete with the anaerobes.