The 87-year-old was hospitalised late last month for an infection while on holiday in Malaysia, and received a temporary pacemaker at a hospital there on March 2.
He was later transferred to Norway for further treatment, where his doctors said a permanent device would be implanted.
"The operation was successful, and the king is doing well," the palace said in a statement.
He will remain in hospital for a few days, the royal court said.
King Harald, Norway's ceremonial head of state since 1991, is Europe's oldest living monarch. He has repeatedly been hospitalised with infections in recent years and has undergone heart surgery.
Crown Prince Haakon has been carrying out his father's duties in the latter's absence.
Read the latest news here