In the 44th minute, Ismaila Sarr scored from penalty spot for Senegal, 1-0.
The Lions of Teranga led the first half at the Khalifa International Stadium, Ar-Rayyan.
Ecuadoran player Moises Caicedo finished in the far post to level the game in the 67th minute.
However, a few minutes later Senegal took the lead once again as their defender and captain Kalidou Koulibaly scored from close range after a freekick whipped from the right flank.
Senegal secured the win to finish Group A in the second position, which meant the Lions of Teranga were into the last 16.
The Netherlands won Group A with seven points in three matches as the Dutchmen toppled already-eliminated Qatar 2-0.
Senegal have six points to join the Netherlands in the knockout stage in Qatar 2022.
Ecuador have four points to be eliminated from the World Cup.
Host nation Qatar lost all their three matches.