But favourite and 10-times champion Rafael Nadal eased past fellow Spaniard Roberto Carballes-Baena 6-4 6-4 in his first appearance at this year's tournament to reach the third round and set a record by winning 38 consecutive sets on clay.
Second seed Grigor Dimitrov of Bulgaria also moved smoothly past Frenchman Gilles Simon 6-2 6-1 to reach the last 16.
Djokovic, who received a bye in the opening round, has not made the last eight of a tournament since last year's Wimbledon and has struggled with a long-term elbow injury.
The 30-year-old lost to Austria's Dominic Thiem in the last 16 of the Monte Carlo Masters last week and looked far from his best in what was his second career appearance in Barcelona.
Klizan claimed the first set in just 32 minutes before Djokovic broke the Slovakian's serve twice to take the second.
Klizan snatched a crucial break in the eighth game of a tense final set and went on to claim his first career victory over Djokovic in five meetings.
"I feel I haven’t lived up to your expectations, not even my own," Djokovic told a news conference.
"It’s hard to deal with these types of games and defeats, I wasn’t playing at my best, only during the second set. I will try to continue and see where it takes me."SLOW START
Rafael Nadal. Source: AAP
World number one Nadal, who also had a bye to the second round, packed out the main court at the Real Club de Tenis in Barcelona which is named after him.
Perhaps still feeling the effects of his triumph in Monte Carlo on Sunday, Nadal made a slow start against Carballes-Baena and was broken in the opening game to fall 2-0 behind.
The Mallorcan responded by breaking twice to take a 4-2 lead and went on to claim the first set. Nadal broke in the opening game of the second set but lost his serve in the sixth.
He went in front again and had match point at 5-3 but could not take advantage, although he comfortably closed the match out with his next service game.
"It was a difficult game and I committed a couple of errors at the start. The first game here after Monte Carlo is always hard but I soon found my rhythm," Nadal told reporters.
The victory saw the Spaniard surpass Romanian Ilie Nastase's record of winning 36 consecutive sets on clay in 1973.
Nadal will now meet another Spaniard, Guillermo Garcia-Lopez, who progressed after 14th seed Kei Nishikori retired from his first match after experiencing pain in his right wrist.
The 28-year-old Japanese, who lost to Nadal in the Monte Carlo Masters final on Sunday, withdrew after losing the first set 6-3.
"My expectations grew in Monte Carlo, despite losing to Nadal," Nishikori told reporters. "However, I started feeling discomfort again during the first set and I did not want to take any risks."
He missed last year's U.S. Open and the Australian Open at the start of 2018 after injuring the same wrist in August.