The story about the origin of Vastu purusha appears in Matsypuranam. During a fight between Lord Shiva and a demon called Andhakasura, another huge demon was born from the perspiration of Lord Shiva. He was Vastu purusha. This happened in the Threthayuga on a Krishnapaksha Triteeya in combination with Krittika nakshatra, Vyateepata nityayoga and Vishti karana. This demon was very huge in size and cruel looking. As soon as he was born, he started feeling hungry. His hunger was insatiable. He started performing severe austerities to propitiate Lord Siva, and when Lord appeared before him, asked for a boon that he should be allowed to consume all the three worlds. The boon was granted. Vastu purusha started out by eating the earth first. The Devas and all other beings found his atrocities unbearable. They approached Brahma. Brahma advised them engage him in a battle at the end of which he fell flat on the earth. Still he was hitting and pounding around causing great destruction. Then all the 53 Devas climbed on top of him sitting on his various organs thus pinning him down. The demon could not move and he prayed to Brahma for relief. Brahma granted him a boon that whenever or wherever a new property is created, a house, palace, temple, fort etc. is built the Vastu purusha can again become active and if propitiated with worship, he will refrain from causing disturbances. Anybody neglecting Vastu purusha and proceeding with construction will suffer the consequences in the form of accident, death, diseases and various obstacles.
Hence at the commencement and completion of any such activity, Vastu purusha is worshiped after invoking the 53 Devas onto his body. This is called Vastu shanthi. which should be performed before entering a new house.