According to the civics text books, a democracy is a government in which the people are sovereign. In its republican forms it elects people who represent them in legislatures, and they work to create the laws that the sovereign people are obligated to obey, whether they like them or not because they were enacted by the representatives that popular majorities elected. If they don't like it, then they have to work to get the laws changed through the same process. That works fine, so long as the game isn't rigged, and the public interest has a chance to be realized.
And so unless you insist on some Rousseauan idea of the 'general will' and how the people are always by definition right, it's been demonstrated time and time again that majorities often get it wrong. Sometimes because they are in a paroxysm of fear or in a patriotic frenzy; sometimes because they have been manipulated by demagogues, the saner, more mature minority does not prevail. The ancient Greeks thought democracy was a form of government that inevitably devolved into tyranny precisely because of its vulnerability for majorities to be manipulated by demagogues who used popular support to obtain power, and then used that power to establish an autocracy. Think Germany or Louisiana in the '30s.
And so it should be obvious that because a government was democratically elected, it does not mean that it has legitimacy.The ballot box confers what I would describe as a provisional legitimacy; it's not absolute. Ultimately legitimacy is conferred in the streets. When elections or the basic elements in the system are rigged, there might be legality, but not real legitimacy, not a legitimacy that means something. I'd argue that George Bush's taking office in 2001 was technically legal, but not legitimate; legitimacy was conferred in the streets when no one took to them.
Egypt is at the mercy of the military, and everything depends on whether it is dominated by actors possessed by the will to power or the public interest. There's good reason to hope for the latter, because they are responsive to the verdict of illegitimacy conferred on the Morsi government by citizens in the streets. There isn't something sacred about democratic elections. If 50% + 1 of your electorate is insane, ignorant, and easily manipulable, you probably shouldn't have them. The Jim Crow south was legal but illegitimate. Democratic elections, I'd argue, have legitimacy only in societies with majorities that possess a basic level of decency, maturity, and civic mindedness, and the jury is out on whether the US has that anymore and whether its government has real legitimacy. Legality does not equal legitimacy.
I'd say a solid 40% of Americans don't have the requisite sanity and decency to endorse a legitimate government, but 40% do, and if at some point the latter don't take to the streets to call out the the way their government is trending toward illegitimacy, they will show themselves to be less mature and civically responsible than Egyptians, Turks, and Brazilians. And as with the Bush election, they are otherwise legitimating the illegitimate by their passivity.