The world number one also went out in the last eight of the Monte Carlo Masters last week, losing to compatriot David Ferrer.
Top seed Nadal showed some form in the first set against Almagro and then lost his way.
Both players broke serve in the opening two games. Almagro hit some deadly backhands but also racked up 15 unforced errors in the set.
The second set was more even and it went to a tie-break with Almagro, who had never beaten his countryman in 10 previous attempts, coming out on top.
The decider was scrappy and contained four consecutive breaks of serve before the sixth seed clinched victory.
"I had a lot of chances in the second set when I had the match more controlled but I didn't take them," Nadal told reporters.
"As the match went on I was less calm but I still had openings in the third set at 3-1 and at 4-4 which I didn't take. This is tennis and you just have to keep going."
Russian Teymuraz Gabashvili, who scored a shock win over world number five Ferrer in the second round, came unstuck against Latvian Ernests Gulbis who triumphed 6-1 6-4 to set up a meeting with Japanese Kei Nishikori.
Fourth seed Nishikori, looking strong in his return from a groin injury, defeated Croatian Marin Cilic 6-1 6-3.
ATP Barcelona Quarter-final results
Santiago Giraldo (Colombia) beat 10-Philipp Kohlschreiber (Germany) 6-4 4-3 (Kohlschreiber retired)
6-Nicolas Almagro (Spain) beat 1-Rafa Nadal (Spain) 2-6 7-6(5) 6-4
4-Kei Nishikori (Japan) beat 12-Marin Cilic (Croatia) 6-1 6-3
9-Ernests Gulbis (Latvia) beat Teymuraz Gabashvili (Russia) 6-1 6-4
- Sports & Recreation
- Philipp Kohlschreiber
- David Ferrer