"I will be in Paris on Sunday to lend support to the French people. Spain together with France against terrorism and for freedom," Rajoy wrote on his Twitter account.
His spokesman said he had been invited by the French government.
The news came as elite French police stormed a printworks and a Jewish supermarket Friday, killing two brothers wanted for the Charlie Hebdo attack and an apparent accomplice who had taken hostages in two separate sieges that traumatized France.
Explosions rocked a small printing firm in the village of Dammartin-en-Goele, northeast of Paris, and smoke poured from the building as the heavily armed forces mounted their assault as night fell.
The two Islamists launched a desperate escape bid, charging out of the building firing at the security forces before being cut down in their tracks, a security source said.
Meanwhile, in the east of Paris, gunfire erupted as police stormed the Jewish store, where at least one armed assailant had seized five hostages after two people were killed in a gun battle.
The gunman was also killed, security sources said, as terrified hostages were seen running out of the store.
The dramatic climax to the two stand-offs brought to an end more than 48 hours of fear and uncertainty in the country that began when the two brothers slaughtered 12 people at Charlie Hebdo in the bloodiest attack on French soil in half a century.
The hostage-taker in the eastern Porte de Vincennes area of Paris was suspected of gunning down a policewoman in southern Paris Thursday and knew at least one of the Charlie Hebdo gunmen.