We present hydrodynamic and magnetohydrodynamic (MHD) simulations of liquid sodium flows in the von Kármán sodium (VKS) set-up. The counter-rotating impellers made of soft iron that were used in the successful 2006 experiment are represented by means of a pseudo-penalty method. Hydrodynamic simulations are performed at high kinetic Reynolds numbers using a large eddy simulation technique. The results compare well with the experimental data: the flow is laminar and steady or slightly fluctuating at small angular frequencies; small scales fill the bulk and a Kolmogorov-like spectrum is obtained at large angular frequencies. Near the tips of the blades the flow is expelled and takes the form of intense helical vortices. The equatorial shear layer acquires a wavy shape due to three coherent co-rotating radial vortices as observed in hydrodynamic experiments. MHD computations are performed: at fixed kinetic Reynolds number, increasing the magnetic permeability of the impellers reduces the critical magnetic Reynolds number for dynamo action; at fixed magnetic permeability, increasing the kinetic Reynolds number also decreases the dynamo threshold. Our results support the conjecture that the critical magnetic Reynolds number tends to a constant as the kinetic Reynolds number tends to infinity. The resulting dynamo is a mostly axisymmetric axial dipole with an azimuthal component concentrated near the impellers as observed in the VKS experiment. A speculative mechanism for dynamo action in the VKS experiment is proposed.