In simple words because the enemy forces were seriously STRONG that ANBU agents were not able to defeat them (as said by Happy Face in the comments).
According to me, Naruto's team is an exceptionally very strong.
Kyuubi's Chakra + Sharingan + Healing = STRONGEST
So there is no doubt that they are stronger. They are exceptionally strong, so we might say that they are stronger than ANBU agents.
When some strong enemies come to their village let's say Nagato, aka Pain, then it's quite obvious that ANBU agents won't be able to defeat him because Nagato is really strong, but Naruto did because he is exceptionally stronger than the ANBU agents.
One of the Fifth Hokage's ANBU bodyguards attributed his chakra supply to the Rinnegan. Nagato could also constantly alter the nature of his chakra to prevent him from being located by sensory type ninjas.
ANBU commander is very observant, seen when he recognises that Pain's chakra-levels must be immense and that he is controlling the bodies used to destroy Konoha by chakra alone.
But that doesn't mean that all anbu agents are nothing. For example Yamato is also an ANBU agent, and if you have seen him then you may have know that he is not easy to be defeated by enemies just because he is strong.
There are many ANBU agents which differ from each other. They are responsible for carrying out assassinations, tracking, surveillance, and missions requiring specially trained ninja. Also some ANBU serve as interrogators.
All ANBU agents have their own skills.
But there's a point that we must note:
ANBU are expected to destroy their bodies when they are badly injured on a mission like that they won't be captured.
Which might explain why they kill themselves every time they are badly hurt. Source
One word, Teamwork, AMBU agents are able to eliminate their comrades if the mission requires them to, The other teams work together & protect each other, this simple aspect makes any team stronger than AMBU.
The problem with the Anbu is that because they all wear masks, they are always essentially anonymous. They have a reputation for being very strong, but because no-one wants to see five anonymous men beat up one budding villain, they never win any fights, only ever being defeated, sometimes by the dozens, to show how strong some other ninja who actually has a name really is.
Comparing Naruto's team to the Anbu doesn't really make a lot of sense, at the beginning of the series their power is basically Kakashi, one of the top jonin in the leaf village, and Naruto sometimes being pretty helpful when his fox chakra comes out. Sasuke is very talented, but is still just a kid, and significantly weaker than any named jonin. As time goes on, Naruto becomes far more powerful, first defeating Nagato which the entire Leaf Village was unable to do, and then becoming basically a God by the end of the series.