She becomes the first unseeded woman to win at Roland Garros since 1933.
The 20-year-old trailed by a set and was 3-0 down in the second to Halep – who would have become world number one with a win – but prevailed 4-6, 6-4 6-3.
Ostapenko, ranked 47th, had never won a Tour-level title before and was playing in only her eighth Grand Slam.
Her victory completed a fairy-tale fortnight that included her 20th birthday and a congratulatory call from Raimonds Vejonis, president of her native Latvia.
The men’s final will be contested between Rafael Nadal and Stan Wawrinka on Sunday.