We prove the almost sure invariance principle (ASIP) with close to optimal error rates for nonuniformly hyperbolic maps. We do not assume exponential contraction along stable leaves, therefore our result covers in particular slowly mixing invertible dynamical systems as Bunimovich flowers, billiards with flat points as in Chernov and Zhang (Stoch Dyn 5:535–553, 2005a, Nonlinearity 18:1527–1553, 2005b) and Wojtkowski’ (Commun Math Phys 126:507–533, 1990) system of two falling balls.For these examples, the ASIP is a new result, not covered by prior works for various reasons, notably because in absence of exponential contraction along stable leaves, it is challenging to employ the so-called Sinai’s trick (Sinai in Russ Math Surv 27:21–70, 1972; Bowen, Lecture Notes in Math vol. 470 (1975)) of reducing a nonuniformly hyperbolic system to a nonuniformly expanding one. Our strategy follows our previous papers on the ASIP for nonuniformly expanding maps, where we build a semiconjugacy to a specific renewal Markov shift and adapt the argument of Berkes et al. (Ann Probab 42:794–817, 2014). The main difference is that now the Markov shift is two-sided, the observables depend on the full trajectory, both the future and the past.