The Moon's role in the rhythmic rising and falling of the oceans along the shore was explained mathematically in 1687 by Isaac Newton.
Ocean tides are caused by the gravitational interaction between the Earth and the Moon. There are two high tides and two low tides each day. During New Moon and Full Moon the difference between high and low tides is more extreme. Those are called spring tides. During First Quarter and Last Quarter phases of the Moon the difference between high and low tides is less extreme. Those are called neap tides.
The key to understanding the tides is exam the consequences of the fact that the Moon pulls harder on the side of the Earth nearest to it, and less on the side of the Earth farthest away.
Imagine a world made completely of water.
Now think about the Moon pulling on the water in sections. The closest water is pulled most strongly, the water that is farther away less so, and the water farthest away the least. This will have the effect of stretching the water out into the shape of a football.
Now let's add our world to the stretched ocean. There is one high tide in the direction of the Moon and another on the opposite side. Since the Earth spins under the Moon every 24 hours, the coast near you will experience two highs and two lows per day. The effect is least dramatic near the poles.
During New and Full phases of the Moon it is lined up with the Sun so the tidal action of the two bodies add together. That is why the effect is most extreme at those times (spring tides). During the first and third quarter phases of the Moon the tidal action of the Moon is somewhat counteracted by the Sun so the effect is less extreme (neap tides).
The reason the Moon has the dominant effect compared to the Sun, is becaue the difference between Moon's gravity on the side of the Earth closest is much greater than the far side, hence the stretching football effect. But for the Sun, the side of the Earth closest is only a small percent different than the far side. The diffence in distance either way is about 8000 miles, which is a large fraction of the distance to the Moon, and a very small fraction of the distance to the Sun.
The timing of high and low tides at a particular place is effected by the water's friction with land masses and the shape of coastlines. Tide charts are custom produced to account for local idiosyncrancies.
The friction of the tides is slowing down the spin of the Earth by a tiny amount each day. One hundred years from now, the day will be 2 milliseconds longer than it is now. Since angular momentum cannot be destroyed, that spin has to be conserved somewhere in the Earth-Moon system. The end result is that the Moon is getting farther away by about 3.8 centimeters per year.