We show that if the second eigenvalue λ of a d‐regular graph G on n∈3Z vertices is at most εd2/false(nprefixlognfalse), for a small constant ε>0, then G contains a triangle‐factor. The bound on λ is at most an O(logn) factor away from the best possible one: Krivelevich, Sudakov and Szabó, extending a construction of Alon, showed that for every function d=d(n) such that Ω(n2/3)⩽d⩽n and infinitely many n∈N, there exists a d‐regular triangle‐free graph G with Θ(n) vertices and λ=Ω(d2/n).