The world number one fought back from a break down in the opening set, taking it in a tie-break, before seeing out a 7-6(2) 6-4 win in one hour and 56 minutes.
"It was a positive victory for me," said Nadal.
"I need to improve everything. I'm working every day to play more aggressively. I need to find the feeling of being dominant in the points.
"I feel that sometimes I'm hitting balls from good positions and I'm not able to create the right spaces, to find winners. I need to try and find that for the next match."
Ferrer, the second seed at the event behind Nadal, lost 6-4 6-2 against the world number 55, losing his serve four times in the two sets as the underdog produced some brilliant returns of serve.
Gabashvili gave his illustrious opponent plenty of chances, but the Russian saved all but one of the eight break points against him.
The defeat was a major shock for Ferrer, who beat Nadal on clay in the Monte Carlo Masters last week before going on to lose in the semi-finals against Stan Wawrinka.
"This was one of my best victories, no in fact it is my best ever, beating David Ferrer," Gabashvili told reporters.
"I went into the game knowing that I had to be steady and controlled which is what I managed to do."
Third seed Fabio Fognini of Italy was the morning's other big casualty in Spain, struggling throughout with injury as he trailed Santiago Giraldo 6-0 4-0 before finally admitting defeat and quitting the match.
ATP Barcelona round 2:
12-Marin Cilic (Croatia) beat Andrey Kuznetsov (Russia) 6-1 7-6(2)
11-Fernando Verdasco (Spain) beat Kenny De Schepper (France) 6-4 6-3
1-Rafa Nadal (Spain) beat Albert Ramos (Spain) 7-6(2) 6-4
Jurgen Melzer (Austria) beat 7-Jerzy Janowicz (Poland) 6-4 7-6(1)
Santiago Giraldo (Colombia) beat 3-Fabio Fognini (Italy) 6-0 4-0 (Fognini retired)
Teymuraz Gabashvili (Russia) beat 2-David Ferrer (Spain) 6-4 6-2
Ivan Dodig (Croatia) beat 13-Feliciano Lopez (Spain) 6-1 6-4
6-Nicolas Almagro (Spain) beat Martin Klizan (Slovakia) 7-5 7-6(4)
Albert Montanes (Spain) beat 8-Alexandr Dolgopolov (Ukraine) 7-6(5) 6-3
ATP Bucharest round 2:
1-Grigor Dimitrov (Bulgaria) beat Jiri Vesely (Czech Republic) 7-6(5) 6-2
Sergiy Stakhovsky (Ukraine) beat Carlos Berlocq (Argentina) 4-6 7-6(5) 6-2
4-Gilles Simon (France) beat Victor Hanescu (Romania) 2-6 6-3 6-3
Lukas Rosol (Czech Republic) beat 8-Jarkko Nieminen (Finland) 6-2 6-4
- Sports & Recreation
- David Ferrer
- Teymuraz Gabashvili
- Fabio Fognini