Extraordinary structural organization known as emergence is observed in partially ordered sets when a recently discovered functional is minimized. Emergence creates the first structures, and feedback reuses them to create hierarchies of structures. The partially ordered set is the knowledge representation, the functional connects local behavior to global phenomena, emergence and feedback correspond to inference, and the structures and hierarchies to objects and inheritance hierarchies. If intelligence includes the ability to solve problems, then the structures represent intelligence and emergence represents the build up of intelligence. Since the structures are mathematically obtained from first principles, the finding is proposed as an explanation for the origin of intelligence, and the functional as the key for AGI. Three previous computer experiments, and another one reported here, duplicate higher functions of the human brain and confirm the findings.