Pep Guardiola's side hit the post and saw a late effort ruled out for a dubious offside decision, and is now six points behind Real Madrid at the top of La Liga.
With all the action taking place in Madrid, Barca saw title rival Real come from behind to thrash Atletico 4-1 in the derby just before this match and needed a win to close the gap back to within three of its fierce foe just two weeks ahead of the Clasico at the Santiago Bernabeu.
But it was a less-than-impressive performance from Pep Guardiola's side, so slick against AC Milan in a 3-2 win in San Siro on Wednesday, and Getafe stunned the visitors as Valera headed home midway through the second half.
Guardiola welcomed back Gerard Pique and Dani Alves in a strong side, with Alexis Sanchez chosen on the right, David Villa on the left and Lionel Messi in the center as Barca began its second successive match in its third kit.
But while the club had looked in mint condition in Milan, it was a subdued showing this time around.
Messi sent an early free kick just wide and was later thwarted as Getafe goalkeeper Miguel Angel Moya saved at his feet, but the hosts were lively as well and Miku came close on two occasions in the opening 45 minutes.
Barca attacked higher up the pitch in the second half, but Alexis was particularly disappointing and Thiago was no match for the missing Andres Iniesta.
Moya saved again from Messi and Valera shot wide at the other end as Getafe looked to do damage on the break.
And incredibly, the home side took the lead after 67 minutes, when Varela headed home from Pablo Sarabia's corner.
Barca rallied after that and pressed forward in search of a late leveller. And it thought it had salvaged the game when Messi converted right at the end, but the flag was raised for a questionable offside and the Catalans were left frustrated.
Messi then diverted a Pedro shot onto the post deep into injury time and there was no way back for Guardiola's men, who suffered their first defeat of the season and are now six points behind Real Madrid just two weeks ahead of the Clasico, which is now surely a must-win affair for the defending Spanish champions.