At the beginning there was only void, then an egg appeared and from the egg Arceus was born.
To shape the universe it created Dialga (to shape time), Palkia (to shape space) and Giratina (to shape antimatter). But Giratina betrayed Arceus so it was banished in a world without time and space.
To shape the other stuff he created other legendary pokemon like Kyogre, Groudon and Rayquaza to create Earth (water, earth and atmosphere).
But the universe was empty so Mew was born, and from Mew all the other pokemon were born.
(this is a mix of real lore and my personal headcanon, that's why it doesn't explain everything and it has a few plot holes
)