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