Nadal struggles past world number 111 Ivashka as Fognini disqualified
The 34-year-old Nadal, who suffered a surprise quarter-final exit at the hands of Andrey Rublev in the Monte Carlo Masters last week, dropped the first set against the world 111 before pulling through 3-6, 6-2, 6-4.
It was Nadal's 62nd win in the tournament against just four defeats.
"He played well. He played at a very high level, and I didn't, especially at the beginning," said Nadal who has lost only once on clay to a player outside the top 100 and that was 17 years ago.
"Then I think I changed a little bit the way I played. I was more aggressive later, and the match changed a lot. "I'm happy I fought hard today to be in the third round. That's what I needed after the loss at Monte Carlo."
In Thursday's quarter-final, Nadal will face Japan's Kei Nishikori, the 2014 and 2015 Barcelona champion, who defeated Chile's Christian Garin 7-6 (7/5), 4-6, 6-1. Nishikori has two career wins over Nadal in 13 meetings but has never got the better of the world number three on clay.
Fiery Italian Fabio Fognini was defaulted from the event for verbally abusing a line judge.
The 33-year-old was trailing world number 147 Bernabe Zapata Miralles 6-0, 4-4 when he clashed with the official and was defaulted by the umpire for unsportsmanlike conduct.
Fognini is one of only a small number of players to have been defaulted from a match.
The most famous incident involved world number one Novak Djokovic who was disqualified from the 2020 US Open for hitting a line judge with a ball.
Nick Kyrgios was defaulted at the Rome tournament in 2019 after hurling a chair on to the court.
At the 2017 US Open, he was booted out of the tournament and fined $24,000 for a series of insults aimed at a female chair umpire.
Elsewhere on Wednesday, Monte Carlo champion and second seed Stefanos Tsitsipas eased past Spain's Jaume Munar 6-0, 6-2.
It was a far more comfortable afternoon for the Greek than the last time he faced Munar.
That was at the 2020 French Open where he dropped the first two sets before winning their first round tie.
Monte Carlo runner-up Rublev, seeded three, also progressed with a comfortable 6-4, 6-3 win over Italian lucky loser Federico Gaio.