It took Croatia just seven minutes to open the scoring through a header from Joško Gvardiol, before Achraf Dari equalized two minutes later.
In an open and exciting game, Croatia retook the lead through a brilliant finish from Mislav Oršić on the stroke of half-time.
Despite its best efforts, Morocco could not find another equalizer, finishing the tournament in fourth place to cap off a memorable few weeks in Qatar where Morocco became the first African nation to reach the World Cup semifinals.
Croatia's third-placed finish is its second at a World Cup, having finished third in 1998. In Russia four years ago Croatia was runner up.
It's the game at the World Cup most teams often don't want to play.
Just days after losing in the semifinals, teams must play again despite hopes of a tournament victory being dashed fresh in their minds.
But for two of this tournament's surprise stories -- Croatia and Morocco -- the drive to finish with a victory was evident from minute one.
Morocco wanted to cap its historic run in style, while Croatia was looking to cement its second third-place finish in six World Cup appearances.
From the outset, defending was at a premium. Having played out a goalless draw earlier in the tournament, within the first 10 minutes at the Khalifa International Stadium both sides had found the back of the net.
First, Croatia's star young defender, Gvardiol, put his side ahead in the seventh minute after a superbly worked free kick. The clipped ball into the area was headed backwards by Ivan Perišić for the 20-year-old to power his side ahead.
However, only two minutes later, Morocco was level, the goal coming from another free kick. After the ball was looped into the area via a deflection, Dari was the lucky beneficiary as he headed home with no Croatian marker in his vicinity.
And the game continued at a furious pace, with Croatia enjoying the majority of possession and chances.
With Morocco's fans once again providing a fantastic atmosphere, chances came and went in pulsating fashion -- Morocco striker Youssef En-Nesyri's header from a corner drifted just wide.
But with a moment of magic, Croatia once again took the lead, this time on the stroke of half-time.
After some scrappy play on the edge of the Moroccan box, a beautifully curled finish off the post from Oršić once again had the European nation ahead.
After the break, the chances continued to flow but neither side fashioned any real goal-scoring opportunities.
On the hour mark, Andrej Kramarić was forced off through injury, with the 31-year-old in tears as he was helped off the field.
With 15 minutes left, Croatia thought it had a penalty when Gvardiol was brought down in the Morocco box after a wonderful run. However, the video assistant referee (VAR) deemed it not a foul, to the amazement of the Croatian players, despite it appearing as if Sofyan Amrabat had clipped the heels of the defender.
In the final few minutes, despite Morocco needing a goal, it was actually Croatia which looked the more likely to score, with Mateo Kovačić coming closest.
But, with almost the final kick of the game, En-Nesyri's towering header flew just over the bar as Moroccan hopes of an equalizer slipped away.
In the end, Croatia was able to hold out for the narrow victory to match the achievement by the nation's so-called "bronze generation" in 1998.
For Morocco, its magical few weeks in Qatar comes to an end, having captured the hearts and minds of a whole continent with its trail-blazing run to the final four of the World Cup.