Let (M, I) be an almost complex 6-manifold. The obstruction to the integrability of almost complex structure N: Lambda(0,1)(M) -> Lambda(2,0)(M) (the so-called Nijenhuis tensor) maps one 3-dimensional bundle to another 3-dimensional bundle. We say that Nijenhuis tensor is nondegenerate if it is an isomorphism. An almost complex manifold (M, I) is called nearly Kahler if it admits a Hermitian form omega such that del(omega) is totally antisymmetric, del being the Levi-Civita connection. We show that a nearly Kahler metric on a given almost complex 6-manifold with nondegenerate Nijenhuis tensor is unique (up to a constant). We interpret the nearly Kahler property in terms of G(2)-geometry and in terms of connections with totally antisymmetric torsion, obtaining a number of equivalent definitions. We construct a natural diffeomorphism-invariant functional I -> integral(M) Vol(I) on the space of almost complex structures on M, similar to the Hitchin functional, and compute its extrema in the following important case. Consider an almost complex structure I with nondegenerate Nijenhuis tensor, admitting a Hermitian connection with totally antisymmetric torsion. We show that the Hitchin-like functional I -> integral(M) Vol(I) has an extremum in I if and only if (M, I) is nearly Kahler.