SB 8.1.18

tāṁs tathāvasitān vīkṣya
 yajñaḥ sarva-gato hariḥ
yāmaiḥ parivṛto devair
 hatvāśāsat tri-viṣṭapam
Synonyms: 
tān — the demons and Rākṣasas; tathā — in that way; avasitān — who were determined to devour Svāyambhuva Manu; vīkṣya — upon observing; yajñaḥ — Lord Viṣṇu, known as Yajña; sarva-gataḥ — who is seated in everyone’s heart; hariḥ — the Supreme Personality of Godhead; yāmaiḥ — with His sons named the Yāmas; parivṛtaḥ — surrounded; devaiḥ — by the demigods; hatvā — after killing (the demons); aśāsat — ruled (taking the post of Indra); tri-viṣṭapam — the heavenly planets.
Translation: 
The Supreme Lord, Viṣṇu, who sits in everyone’s heart, appearing as Yajñapati, observed that the Rākṣasas and demons were going to devour Svāyambhuva Manu. Thus the Lord, accompanied by His sons named the Yāmas and by all the other demigods, killed the demons and Rākṣasas. He then took the post of Indra and began to rule the heavenly kingdom.
Purport: 

The various names of the demigods — Lord Brahmā, Lord Śiva, Lord Indra and so on — are not personal names; they are names of different posts. In this regard, we understand that Lord Viṣṇu sometimes becomes Brahmā or Indra when there is no suitable person to occupy these posts.