For everyday purposes, there are exactly 86,400 seconds in a day (midnight to midnight). But, the rotation of the Earth about its axis and the path of the Earth around the Sun aren't exactly either uniform or stable. The rotation of the Earth is very gradually slowing, and there are a number of factors which make "midday" by solar observation sometimes more, sometimes less than 86,400 seconds from the preceding solar "midday". If you average over a solar year, sure, you'll get very close, but over a number of years, you'll see variation.
For scientific and engineering purposes, the fundamental unit for the measurement of time (the second) must have a fixed definition, not one that gets updated every few years just to keep in step with the occurence of solar midday. So, atomic clocks were developed to provide a stable reference against which the second can be defined once and for all (until or unless it is found that current atomic clocks are not a stable enough reference and there is some other measureable phenomenon which is even more stable).
For what it's worth:
Leap years have nothing to do with the second as a unit of time. Leap years occur because the rotation of Earth about its axis (from which we get our day) and the orbit of Earth around the Sun (from which we get our year) are not related by an integral number, and we want to keep our calendars in alignment with the natural day and year.
Leap seconds occur because we want to divide our mean solar day evenly into hours, minutes, and seconds, and the mean solar day is gradually getting longer (the Earth's rotation is gradually slowing), but we don't want to modify our definition of the second. Leap seconds are added on an "as-needed" basis, which occurs somewhat irregularly because there are a number of factors affecting the Earth's rotation.