The Intel Core i5-8400 wins in 6 out of 14 comparable specs, with 5 ties. Its biggest advantage is Total Cores (50% better).
Core i7-6700K wins in 3 specs (Base Clock: 43% better).
Recommendation
Choose Core i5-8400 if you want the best overall performance — especially total cores.
Choose Core i7-6700K if base clock matters more to you.