They easily overran the Medes, Babylonians, nomadic tribes to the north, and the Lydians. Why was it that the Achaemenid met their match in Greece?
To properly answer this question, we have to actually ask ourselves what failures the Achaemenids actually experienced, as well as any general difficulties. The reason for that is that when treating Darius' and Xerxes' campaigns as failures they are often not examined in depth as to exactly what failed within them, what objectives were not met. I would argue that least initially, Xerxes fulfilled a number of his initial objectives. However, I would still call both expeditions failures, and through exploring that I think we can give a basis for an answer to your question.
The initial expedition began with occupations of Greek islands, along with a renewed presence in Thrace and Macedon. This was done without great difficulty. Darius also opened negotiations, given the strength of his position, but both Athens and Sparta killed his ambassadors. This then altered the original idea- initially a number of Greek cities were being punished for interference in the Ionian revolt, but after Athens and Sparta did such things their punishment was sealed. The full attack on Greece successfully attacked Naxos, pacified Delos, attacked Karystos on Euboea and made them capitulate, besieged and took Eretria on Euboea due to treachery, then landed at Marathon. There they were defeated; the disaster was not total, but it represented a halt to this expedition against the Greeks.
Now, it's worth pointing out that the Persians army had done a lot of what it sought to do- subjugating Greeks and enacting vengeance on states that had aided rebels during the Ionian War. Herodotus' numbers for the expeditionary force are never given, but his given numbers of triremes (600) would presume a force of perhaps 26,000 men at most which is a fairly reasonable figure. We tend to discard other ancient estimates of 200,000 men as ridiculous. Herodotus' own estimation of Persian casualties was around 6,000 men, which would be around a quarter of the army's strength or less. Modern estimates trend towards 4,000-5,000, which is a lower proportion still. In other words, the Persians did not actually lose many men. However, it is worth pointing out that 20-26,000 men is not an enormous army for the Persians- this has the makings of a reasonably well equipped and semi-professional expeditionary force, not the full royal army. It was no doubt expected to succeed in perhaps grander fashion, but we are not dealing with the full might of Persia concentrated against Athens. Athens and Plataea together put forth around 11,000 men onto the field by themselves, and you can plainly see that this force was always unlikely to conquer the whole of Greece by itself.
But this was still an embarassing setback. Perhaps Darius had indeed assumed that the expedition would achieve a much more comprehensive solution to his issue. Darius did not get the chance to try another attempt, dying within 4 years of the battle. Thus we pass to his son Xerxes' expedition.
The march across the Hellespont was totally unopposed, and supplies had been laid out for the expedition well in advance. For that initial 480 BC campaign season therefore, Xerxes was probably able to field anywhere between 150,000-200,000 men, and this is a flying-the-flag royal army. Whether we believe Herodotus that the King of Macedon warned the defending Greeks of them being overrun or not, Thessaly was abandoned by the Greeks defending against Persia and thus Thessaly submitted. Many cities, in fact, submitted to the Persians rather than fight them. However, Thermopylae caused the Persians a delay of several days- given how slow a march is with an army of that size, this was certainly not a desirable outcome for them. The Greeks, as it happens, could not afford to sacrifice an army of c.5,000 hoplites even in this cause; even after the pass bypassing the Greeks had been discovered, Thermopylae was actually fortified at both ends and could conceivably have held out a long time delaying Xerxes even further. But the Greeks would have certainly been lost there one way or another. So the Greek strategy of taking the Persians head on was extremely risky and had to be very carefully judged. The Persians, in this campaign, were also fighting Greek fleets- the Athenians and Corinthians both now had large navies, and by the standards of the day the Greek fleet actually put to sea was quite sizeable. Whilst Thermopylae was ongoing, the Greek fleet eventually fought the Persians at Artemisium, and whilst they gained no clear victory Herodotus does assert that they inflicted pretty much equal casualties on the Persian fleet. Nonetheless, the Persian occupation of Greek continued- Boeotia submitted, and those cities that did not were destroyed. Attica was next- Athens was razed to the ground, and now only Sparta of the two ambassador-killing cities remained standing. But it's not long afterwards that the battle of Salamis occured at sea, and the Persians lost. Again, this is not a total disaster- this is not the loss of the entire fleet. However, this did represent a significant loss of sea power and a much lesser ability to protect the pontoon bridge that had enabled the crossing into Europe. It's also at this point that Xerxes and his army has to return. Now, the victory at Salamis is often cited as why, and I'm sure it certainly contributed. But even with the supplies being set out in advance, the Persian royal army could not remain in Greece indefinitely. The king most certainly couldn't- Greece was a frontier, not a capital, and even though the Empire could be governed in his absence he was still its epicentre. In addition, the army that Xerxes brought probably included a large number of additional levies who would need to be returned to the Empire. Not that they'd couch it in such terms, but the removal of so many from the Empire would have had a really massive impact on its economy, not to mention the continued expense of feeding, clothing, and partially arming the army. But even after this, most of Greece was pacified and/or submitted. Mardonius, remaining with a smaller occupation force, might well have been reasonably confident. The task was nearly complete. But he did not have the naval supremacy to allow a landing beyond the Isthmus wall that had been build to protect the Peloponnese, and the Greek allies were still mostly intact (by the skin of their teeth). His army was then defeated at Plataea by the largest force of hoplites yet assembled by a Greek army, some 40,000 hoplites of various origins, and the remaining Persian fleet was defeated at Mycale. The expeditionary force was removed, and Xerxes was (fairly justifiably) not seemingly in a mood to spend such effort on another ruinously expensive expedition to what was to him the frontier.
My main issue here has been to establish that actually on both occasions the Persians came close to achieving their objectives in the scope of the resources available on both occasions. However, you have to remember that to the Persians the Greek world was the frontier. It was thousands of miles away from Persia or any of the Persian capitals. It was also nowhere near as rich, developed, or strategically important as most of the Empire's active possessions. This was not Egypt where multiple expeditions could be raised to recapture it when it revolted. It is pretty much exactly the equivalent of the Romans constantly attacking the deeps of Germania- whilst expeditions occurred, they were certainly not constant. In addition, the Greeks facing Xerxes' expedition in particular made some wise choices- they preserved the core alliance rather than breaking up, they persevered despite in some cases exile from their own cities, their methods of warfare were still mostly unfamiliar to the Persians and well suited to their own home turf, they realised that naval power was deeply important to the conflict. They also avoided catastrophic defeats, along with open-battle confrontations with the full Royal army- their pitched battle at Plataea was against Mardonius' satrapal army, against which they could presume more reasonable parity.
I do not really think the Achaemenids performed poorly. I would however say that their resources were stretched purely attempting to operate in Greece- none of the carefully constructed administrative and logistical network of the Empire existed there, Greece was really not very rich in that era by comparison to the Empire or fertile for that matter, and the primary intention of the expeditions were to pacify a troubled frontier of the Achaemenid Empire. Their impetus for acting in Greece was the Greek interference in the Ionian revolt, and internal affair- you are not going to leave powers attempting to affect your own state's internal workings unmolested. Greece was never going to be the equivalent of Media, Babylonia, and Lydia- settled regions with much to offer the Empire, and importantly MUCH closer to the Empire's capitals.
I don't think that Greece was ever, in this period, a match for Persia. If they had really considered it worth their time, the Persians could have just simply sent invasion after invasion. It's important to remember that only one Persian expedition came over the sea, and it almost succeeded. I don't think the successful resistance of a Greek coalition (it was never the Greeks as many capitulated or sided with them, and indeed Herodotus says that the Persian army at Plataea had Greek allies) was inevitable. But I also don't think the Persians were ever prepared to send army after army for a frontier land of rocky shores, poor soil, mountainous terrain, and very little riches. The primary purpose had always been to a) pacify Greece and b) to enact punitive measures on the specific states that had been assisting the Ionian rebels in their revolt.