In the first movie, the guards are the main security force of Agrabah, mainly keeping the royal family safe or trying to stop thieves from stealing. The Royal Guards are also shown to keep trying to arrest a certain street rat that always gets away from them; Aladdin. Later, by Jafar's orders they eventually find Aladdin's hovel and arrest him, but at the same time they also find Princess Jasmine, who had earlier escaped from the palace. When she orders them to release him, Razoul, The Captain of the Royal Guards apologizes saying they can't and escort the Princess back to the palace.
For the rest of the film, the guards don't do much, having only a minor /recurring role, but some of them along with Razoul do appear when a disguised Aladdin who goes under the name of "Prince Ali" arrives in the city, seeking Princess Jasmine's hand in marriage. Later on after Aladdin and Jasmine arrive back at the palace after going on their first carpet ride together, the guards under Jafar's orders kidnap Aladdin, knock him unconscious and throw him off a cliff. It's most likely that Jafar had hypnotize the guards into doing these deeds or lied to them saying "Prince Ali" was up to no good. After that the guards don't appear for the rest of the movie.
In the second film, despite being engaged to marry Jasmine, the guards haven't changed their opinion of Aladdin, seeing him nothing than a mere "street rat" as they always have. They are shown to have again a bit of a minor/recurring role as they had in the first film. They first appear trying to arrest the thief Abis Mal who then escapes in a wagon carrying chickens and eggs and then later appear when the Sultan tries have the guards arrest Iago. Later, when Aladdin arrives back at the palace to let everyone know that the Sultan had been kidnapped, the guards however have been deceived by Jafar, arrest Aladdin believing him to have murdered the Sultan. Later, the guards under "Princess Jasmine's" orders are to have Aladdin die as punishment, when really it was Jafar disguised as Jasmine, when the real princess had already been captured and locked in Jafar's lair. However, thanks to Iago, he was able to free Genie and thus saved Aladdin before he was killed by Razoul and they are been severely punished by the Sultan for falling into Jafar's tricks.
After helping the unconscious Aladdin in the desert and visiting Agrabah, the player can talk to the Palace Guards for the first time. The guards explain that the city is under attack of the Heartless and that the defense is not going well. The Heartless seem to be emerging from a legendary cave on other side of the desert and after the attack on some of their comrades, they ask the player to follow their footsteps in the desert to find the attacker. The player arrives in time to save a guard from a Fat Bandit who reveals, that the Heartless are appearing in the royal palace too.
As it turns out another Fat Bandit is already marching to the palace gates with the guards being unable to stop him. The player also defeats this one but is repelled by an unknown Heartless. Gladly Aladdin arrives just in time to help the player against this new foe but before being destroyed, the Heartless vanishes.