The purpose of the government is to keep the branches equal in power and to enforce laws and manage the military. They got their power from the people, by them voting.
According to the Declaration of Independence, governments derive "their just powers from the consent of the governed." This principle, known to political theorists as "popular sovereignty," is what separates a legitimate government from one that is not.