The substance/gas produced at the end of photosynthesis depends on the electron donor split at the begining of the reaction.
In most organisms like red algae, blue-green algae and C4 plants electrons for the electron transport chain are obtained by the splitting of water and oxygen acts as a final acceptor of electrons causing its release after the process.
In photosynthetic bacteria, other compounds like hydrogen sulphide is used as an oxygen donor leading to production sulphur.