Media reports said Gayoom was unhurt after the incident and that the attacker was in custody.
Shareef said that "the knife did catch his [Gayoom's] shirt".
"He was saved by a boy who moved in the way and tried to grab the knife and suffered a serious injury to his hand."
In the capital Male, Mohamed Nasheed, the Maldives' information minister, said : "The president was greeting people when a young boy pulled out a knife and tried to stab him in the stomach."
The motive for the attack was not known, police said. They said that investigations are being conducted.
The Maldives, a top destination for tourists and honeymooners, has been tense since a bomb attack in September last year injured 12 foreign tourists.
Three men convicted of carrying out the bombing, said to be the holiday archipelago's first ever "terror attack", were last month each jailed for 15 years.