Thiago's winner came 11 minutes after substitute Keaton Parks headed in an 84th-minute equalizer off a corner kick for his first goal of the season.
Thiago, the 20-year-old Brazilian signed from EC Bahia in April, completed a second consecutive victory for NYCFC and lifted them into fourth in the Eastern Conference standings.
Nigel Robertha scored his first MLS goal early into his first start for D.C., which saw a modest three-game unbeaten streak snapped.
The 22-year-old Robertha joined D.C. to start the season after spending the previous two years with Levski Sofia in the Bulgarian first division.
Both teams appeared to lose players to injury during the first half, with D.C. midfielder Moses Nyeman exiting in the 35th minute and NYCFC attacker Jesus Medina departing in the 37th, replaced by Thiago.
New York had arguably the better of the second-half chances, but did not seriously threaten goalkeeper Bill Hamid's goal after the break until Keaton Parks' equalizer.
As Maxi Moralez took the 84th-minute corner on the right, Parks snuck toward the near post and then flashed a header across Hamid's goal and inside the far post from about 6 yards out.
Thiago followed with an extraordinary winner in the fifth minute of second-half stoppage time, just after Sean Johnson had denied a point-blank D.C. opportunity on the other end.
Johnson collected the ball and threw it wide right where Thiago was 1-on-1 with D.C. defender Donovan Pines.
Thiago was first to the ball and got to the right of Pines, cut back against the grain, then drove a low finish past the charging Hamid inside the left post.
Robertha put D.C. ahead in the ninth minute after racing on to a long diagonal service from Nyeman.
Robertha brought the ball down with his foot in the left side of the penalty area, dribbled wide to create space from the defending Maxime Chanot, then unleashed a ferocious strike that beat Sean Johnson to his top near-post corner.