The Intel Core i7-14700K wins in 10 out of 14 comparable specs, with 1 tie. Its biggest advantage is L2 Cache (1767% better).
Core i5-8400 wins in 3 specs (Max Turbo Power: 74% better).
Recommendation
Choose Core i7-14700K if you want the best overall performance — especially l2 cache.
Choose Core i5-8400 if max turbo power matters more to you.