Koulibaly scored three minutes after Moises Caicedo had evened the score at 1-1.
In a must-win match for the African champions, Senegal took the lead after a first-half penalty by Ismaila Sarr. Caicedo scored his goal in the 67th.
At 1-1, Ecuador would have advanced from Group A and Senegal would have been eliminated.
The Netherlands beat Qatar 2-0 in the other match to win the group. Senegal finished second while Ecuador and Qatar were eliminated.
Senegal last advanced from the group stage at the 2002 World Cup, when the team reached the quarterfinals in their tournament debut.