NEW YORK — Two points from defeat against Venus Williams at the U.S. Open, Sloane Stephens summoned her best strokes when she needed them the most to reach a Grand Slam final for the first time.

Stephens was so close to defeat before taking the last three games of a back-and-forth semifinal between two Americans at Flushing Meadows, edging seven-time major champion Williams 6-1, 0-6, 7-5 Thursday night.

She will face No. 15 Madison Keys, who beat No. 20 CoCo Vandeweghe in straight sets, 6-1, 6-2.

At 37, Williams was attempting to become the oldest woman to win a Grand Slam title in the Open era, which dates to 1968. She was trying to reach her third major final of this season, something she last did 15 years ago. Here’s how long and successful her career has been: Williams’ first title match in New York came in her U.S. Open debut in 1997. Stephens was 4 at the time.

And Williams was quite near to beating Stephens. With Williams ahead 5-4 and Stephens serving at 30-all, they engaged in a 25-stroke point. Stephens conjured up a backhand passing winner down the line, then wheeled and pumped her fists.

At 5-all, Stephens broke with the help of a lob winner that drew a standing ovation from the crowd and a full-sprint get of a short ball that she turned into a “How-did-she-do-that?!” winner at an impossible angle to get to love-30.

Soon enough, Stephens was serving out the biggest win of her career – and of her impressive comeback from surgery on her left foot in late January. She returned to the tour at Wimbledon in July, losing in the first round, and lost her next match, too. Her ranking, which reached a high of No. 11 in 2013, dropped out of the top 900.

But since then, Stephens has won 14 of 16 matches.

On Saturday, Stephens will meet Keys in the first all-American U.S. Open women’s final since 2002, when Williams and her sister, Serena, faced each other. Keys and Vandeweghe played the second semifinal later Thursday night and neither had ever been to a major final.

This was the first time in 36 years that all four women’s semifinalists at the U.S. Open represented the host country, so it was understandable if spectators in Arthur Ashe Stadium were conflicted about which players to pull for.

Williams vs. Stephens was a back-and-forth affair, with a pair of lopsided sets leading up to a classic third. Just when it seemed one woman or the other was in full command, the match would swerve in a new direction.

Both hit the ball hard. They both covered so much ground, Williams getting to seemingly unreachable balls thanks to her long wingspan, Stephens doing the same thanks to her speed. ► They cheered for Williams when she was shown on the arena’s video boards for a brief pre-match interview in the hallway that leads from the locker rooms to the court entrance. They roared for Williams during introductions after politely applauding Stephens. And they got louder than ever when Williams finally began to work her way back into the match early in the second set.Stephens showed signs of jitters during the warmup, dumping her first two practice forehands into the net. Then she double-faulted on the second point of the match.Yet it was the far more experienced Williams who was far shakier in the early going, ceding the initial break to trail 3-1 thanks to four consecutive shots that went awry. The 24-minute opening set was not much of a contest, thanks mainly to miscue after miscue by Williams — she had 17 unforced errors by the time it was over, 12 more than Stephens.Williams couldn’t calibrate her groundstrokes properly. She failed to put into play returns of second serves delivered in the low 70s mph. Her own serve, usually her most effective stroke, was off, too.And things did not begin all that auspiciously for Williams in the second set, either. She whiffed on a windmill swing at a ball over her head and added a double-fault along the way to facing three break points in the first game, any of which Stephens could have turned into a daunting lead of a set and a break.But Williams saved all three, held there, and broke for the first time to go up 2-0 when Stephens double-faulted. The entire complexion of the match changed right there, and the second set was the polar opposite of the first.Suddenly, everything Williams tried worked, and Stephens was unable to do much of anything right. On one terrific exchange, Williams reached out for a reflex volley winner that even Stephens applauded. Soon after they were headed to an enthralling third set. ◄