Sergio Busquets put Barca ahead in the ninth minute of a first half they dominated but Betis responded well in the second half and they took advantage of Dani Alves' sending off in the 53rd minute.
The impressive Ruben Castro scored two sublime goals in three minutes and Betis were on course for victory before Keita headed home 90 seconds into injury time.
Guardiola was grateful to Keita afterwards: "He probably deserves more. He's a very dependable player in every regard. He gives us things that other midfielders don't have. I'm pleased with his game and, in general, the team's work."