tams tathavasitan viksya
yajñah sarva-gato harih
yamaih parivrto devair
Translation by His Divine Grace A. C. Bhaktivedanta Swami Srila Prabhupada:
The Supreme Lord, Visnu, who sits in everyone’s heart, appearing as Yajñapati, observed that the Raksasas and demons were going to devour Svayambhuva Manu. Thus the Lord, accompanied by His sons named the Yamas and by all the other demigods, killed the demons and Raksasas. He then took the post of Indra and began to rule the heavenly kingdom.
Purport by His Divine Grace A. C. Bhaktivedanta Swami Srila Prabhupada:
The various names of the demigods — Lord Brahma, Lord Siva, Lord Indra and so on — are not personal names; they are names of different posts. In this regard, we understand that Lord Visnu sometimes becomes Brahma or Indra when there is no suitable person to occupy these posts.