The transfer of electrons through a series of electron donors and acceptors, generating energy that is ultimately used for synthesis of ATP, as it occurs in the mitochondrial inner membrane or chloroplast thylakoid membrane.