WASHINGTON — When Ryan Zimmerman, the Washington Nationals first baseman, was a young boy playing baseball in his backyard, he often imagined that he was in the World Series.

Two outs. Bottom of the ninth. Victory just one play away. It was high drama and his team — he recalled that it was either the Baltimore Orioles or the Atlanta Braves — won every time.

“No matter the scenario,” he said with a laugh. “It always had that perfect ending.”

Zimmerman, 35 and a veteran who has been with the Nationals since the team arrived in Washington in 2005, has been waiting 14 years for that perfect ending here. Considering the team began this season with a 19-31 record, it didn’t seem that this would be the Nationals’ year.

But Mark Lerner, the Nationals’ principal managing owner, called it “some kind of magic” as the team turned its horrendous start into a fairy tale that’s near its end. The team won a nail-biter wild-card game. It beat the Los Angeles Dodgers in a Game 5 eliminator for its first victory in a division playoff series, after faltering in four previous tries.