Prior to the Sun, Moon, Ultra Sun & Ultra Moon arc, Necrozma gave off a vast amount of light that was enough to illuminate all of Ultra Space. The ancestors of humans living in Ultra Megalopolis decided to use their scientists to gain control of the Prism Pokémon and attacked it. The battle caused Necrozma to lose a part of its body. When it attempted to heal, light would leak from its wound and Necrozma consumed all of the light in Ultra Space from its attempts. The ancestors of Ultra Megalopolis then built Megalo Tower and managed to gain control of Necrozma with the help of artificial light. Necrozma and the ancestors then realized that in order for the Prism Pokémon to heal itself, it would need to fuse with the incarnations of the sun and moon and absorb their light energy.
Necrozma was mentioned in name by Rotom Pokédex in Unleashing the Incredible Z-Move, where it had heard its name from Xurkitree.
Necrozma first appeared from an Ultra Wormhole in Summon the Emissaries of the Moon and the Sun. It grabbed Solgaleo and Sun and dragged them inside. After taking Solgaleo into the Ultra Wormhole, Necrozma fused with Solgaleo to become Dusk Mane Necrozma. Necrozma then traveled to Ultra Megalopolis, where it attempted to absorb energy from Solgaleo to regain its true strength on top of the Megalo Tower. Six months later, Lunala arrived in Ultra Megalopolis with Sun and Moon and battled a Stakataka that had entered the city. The battle alerted Necrozma, who released Solgaleo and leapt from the Megalo Tower to try and absorb Lunala as well. Lunala tried fighting back, but was quickly overpowered by the Prism Pokémon. Sun and Moon sent out their Pokémon to help, but were stopped by Lusamine. Eventually, Lunala was absorbed by Necrozma, causing the latter to become its Dawn Wings form.
After successfully fusing, Lusamine attempted to capture Necrozma. Necrozma managed to flee to the top of Megalo Tower and opened an Ultra Wormhole that lead to Mount Lanakila. Once entering Alola, Necrozma absorbed the rest of Lunala's energy and released it onto Mount Lanakila. Soon after, Necrozma confronted Zygarde. After a short fight, Necrozma abosrbed the energy from Dulse to turn into Ultra Necrozma. Despite Zygarde's best efforts to keep Necrozma from fleeing and absorbing Alola's light, Zygarde was blown apart by Necrozma's Photon Geyser, reverting it back into Cells.
In Regeneration!! The Power of the Sun and the Moon!, Solgaleo jumped through the Wormhole, where it teamed up with Sun to fight Necrozma. Linking with his aura, Solgaleo attacked the Prism Pokémon with multiple Sunsteel Strikes, but was quickly overpowered. Before Necrozma could finish off the Sunne Pokémon, Zygarde attacked, having reformed into its 50% Forme. Necrozma quickly dropped Zygarde to half of its stamina and it reformed back into its Complete Forme. Shortly after, Moon arrived and gave Solgaleo a Max Revive while her Decidueye trapped Necrozma with Spirit Shackle. With Necrozma's movements stopped, Zygarde teamed up with Solgaleo and Lunala and defeated the Prism Pokémon. After its defeat, it was captured by Zossie. With Necrozma no longer a threat, the Ultra Beasts returned to their worlds.
Several months later, Moon was left in charge of Necrozma's treatments.