Speaking to thousands of supporters hours after being freed, Waqef said the president was in good health and urged the people to continue fighting to restore the democratically-elected government.
"The president thanks you for your untiring fight, your strong fight to restore constitutional order," he said.
Waqef's release comes after a meeting on Sunday when diplomats from the United States, France, Germany and Spain met General Mohamed Ould Abdel Aziz, the coup leader, to demand the release of the detained politicians.
The military also freed the interior minister and two other officials on Monday afternoon but refused to release Abdallahi and said it had no immediate plans to let him go.
Aziz launched the coup last week an hour after Abdallahi fired the country's top four generals, including him, following an increasingly bitter standoff between the president and the army.
Abdallahi, who last year won Mauritania's first free elections in over 20 years, had opposed the military's subsequent plan to hold elections on grounds that the president had failed to govern the country.