A god or deity was a being with principal religious significance. Gods were often perceived to have power over aspects of natural or spiritual existence, and may be the subject of worship or prayer. A multitude of gods have been developed by various cultures.
In Human cultures
On Earth, gods ranged from those with names and specific areas of expertise to the omnipotent God of Christianity and Judaism, to spirits believed extant within aspects of nature (paganism of various sorts), to powerful alien beings. An alternate name for God was the Lord, or when praying directly to him, simply Lord.
Often, one being's god was another being's myth. Sometimes, one being's god was merely another being's powerful alien, as was the case of many of the gods worshipped on Earth. This was the case with Apollo and Kukulkan. (TOS: "Who Mourns for Adonais?"; TAS: "How Sharper Than a Serpent's Tooth")
Where a situation existed in which an individual had no other choice and had to kill to protect themselves or another, that individual might ask a god for forgiveness. In 2266, Doctor Leonard McCoy said, Lord, forgive me, before he killed the M-113 creature. The doctor was saving the life of Captain James T. Kirk. (TOS: "The Man Trap")
In non-Human cultures
The Bajoran people worshiped their Prophets as gods, although to most non-Bajorans, the Prophets were simply powerful beings referred to as "wormhole aliens". For them Captain Benjamin Sisko was their "Emissary", the person who was chosen by the Prophets to lead the Bajoran spiritual life. (DS9: "Emissary", "In the Hands of the Prophets")
The mythology of the D'Arsay contained an epic drama involving Masaka, a sun goddess, and Korgano, a figure implied to be a moon god. Picard's dealings with this drama imply that Masaka was seen as a malign goddess, with Korgano as the benign counterforce that kept her in check. (TNG: "Masks").
The Founders of the Dominion genetically engineered their servant races, the Jem'Hadar and the Vorta, to revere them as gods as a means of control. The Vorta were fully aware of this and saw it as only natural for their gods to compel worship. Conversely, these races dismissed the spirituality of other species. (DS9: "The Jem'Hadar", "Hippocratic Oath", "To the Death", "Tears of the Prophets", "Treachery, Faith and the Great River")
During the late 2370s, the USS Voyager became trapped in orbit around a planet, where time on the surface moved at an accelerated rate. Some of the planet's ancient inhabitants were able to see the starship in the sky, and began to regard it as a deity or god, even setting aside a specific fruit which was only to be offered to the new deity, which they initially called the "groundshaker." Later on in Kelemane history, after they had developed telescope technology, they discovered that the "groundshaker" was actually a vessel, which they called the "Sky Ship." (VOY: "Blink of an Eye")
The Klingons at one time had gods, but according to legend, the gods were slain by the Klingon warriors they had created (led by Kortar, the first Klingon) as "they were more trouble than they were worth." (DS9: "Homefront", "You Are Cordially Invited"; VOY: "Barge of the Dead")
In 2265, following an encounter with the Galactic barrier, Lieutenant Commander Gary Mitchell and Dr. Elizabeth Dehner of the Federation starship USS Enterprise developed incredibly strong psionic powers. Mitchell, becoming completely mad with power, believed he had evolved to a God-like state and used his power to force Captain James T. Kirk to pray to him as one. Dehner, herself, lamented to Kirk that he had no idea what it's like to be almost a God. (TOS: "Where No Man Has Gone Before")
In 2287, Sybok began the final leg in his quest to find God, whom he believed was located at Sha Ka Ree in the galactic core. It is however discovered that Sybok's god, though seemingly well versed in the Gods of the Universe, was in fact a malevolent entity who, himself, was on a quest to obtain a starship and leave his confinement. (Star Trek V: The Final Frontier)
In 2369, Q claimed to Picard that he was in fact God when Picard was having a near death experience after being wounded. Despite Q's admittedly all-powerful nature within our plane of existence, Picard retorted, "No. I am not dead. Because I refuse to believe that the afterlife is run by you. The universe is not so badly designed." (Given the fact that this occurred while Picard was in a near-death state, however, it is possible that this was all an hallucination and Q never really made such a claim.) (TNG: "Tapestry") On Brax, Q was referred to as "The God of Lies". (DS9: "Q-Less")
Gene Roddenberry was known to be a humanistic atheist or agnostic, and debunking both Human and alien gods and superstitions was a regular theme in his stories. Episodes such as TOS: "The Return of the Archons", "Who Mourns for Adonais?", "The Apple", TAS: "How Sharper Than a Serpent's Tooth", Star Trek: Phase II: "In Thy Image", and TNG: "Justice", would show a god as actually an alien or a machine (or both). In an interview with StarTrekAnimated.com, scriptwriter David Gerrold complained that, "when in doubt, Gene always had Kirk get into a fight with God."