He also cancelled an investigation into claims of abuse of power revealed by covert recordings, saying he wanted to "put an end to the agony" ahead of early elections in June.
But his move was condemned both by the opposition and by EU officials.
Macedonia has been in turmoil since the recordings were released in 2015.
In a televised address on Tuesday, President Ivanov said he acted to "defend national interests".
"I've decided to put an end to the agony and, metaphorically speaking, to cut a knot,'' he said, without referring to any politicians by name.
Opposition leader Zoran Zaev said the move was illegal, urging protesters to gather in the capital Skopje. A crowd of several hundred people later gathered outside the prosecutor's office.
Meanwhile, EU Enlargement Commissioner Johannes Hahn said: "Today's actions of President Ivanov are not in line with my understanding of rule of law."
Mr Hahn added that the move put Macedonia's EU membership ambitions at risk.
The crisis was sparked by covert recordings which appear to show ministers plotting vote-rigging and the cover-up of a murder.
Mr Zaev has been releasing a steady stream of recordings since February 2015, accusing the government of wiretapping 20,000 people, including politicians, journalists and religious leaders.
He says that scores of leaked recordings reveal corruption at the highest levels of government, including the mismanagement of funds, dubious criminal prosecutions of opponents and even cover-ups of killings.
The government denies the accusations, and in return has accused Mr Zaev of trying to "destabilise" the Balkan nation.
He rejects the claim.

Gwen Thomson, 51, from Torry, died after the accident on Market Street on Wednesday morning.
Insp Jon Barron said: "Our thoughts are very much with Gwen's family, friends and work colleagues at this very sad time."
The 60-year-old male lorry driver was uninjured. Police Scotland thanked those who helped at the scene.
Insp Barron added: "We have spoken to a number of witnesses to the incident already.  However, I would urge anyone who hasn't yet been in contact with us to do so in order to help piece together exactly what happened."

The 22-year-old was one of six men arrested as part of an investigation into spot-fixing by the National Crime Agency and bailed until April 2014.
Montano, who had been at Boundary Park since the summer of 2012, was suspended without pay by the Latics following the initial allegations.
The former West Ham trainee made 48 appearances, scoring four goals.
A club statement read: "After a thorough investigation carried out by Oldham Athletic Football Club relating to the conduct of Cristian Montano, a decision has been made by the board to dismiss the player forthwith.
"Oldham Athletic take matters such as this extremely seriously and believe it was essential to act as swiftly as possible."
Director Barry Owen told BBC Radio Manchester: "It's been a very difficult week for the club. It's not an easy decision that we've had to make, but it's been made.
"We've got to move on. We've got a big FA Cup tie tomorrow evening [against Mansfield] and the lads are up for it. We've got to move on. We've made the decision and we believe that's the right decision for our fans and the football club.
"I just hope that people realise we've acted positively, and not hastily may I add."
Macedonian President Gjorge Ivanov has issued a pardon to all politicians embroiled in a big corruption scandal that sparked a major political crisis.
[NEXT_CONCEPT]
A woman who died after being knocked down by an HGV in Aberdeen city centre has been named.
[NEXT_CONCEPT]
League One club Oldham Athletic have confirmed that they have sacked winger Cristian Montano.