Terry and Lampard's goals had put the Champions League winners 2-1 ahead in the second half but the MLS All Stars hit back to draw level before snatching a late winner.
Chris Wondolowski, Chris Pontius and Eddie Johnson scored for an All Stars side which featured David Beckham and Thierry Henry.
San Jose Earthquakes forward Wondolowski opened the scoring with a shot after 21 minutes but Terry levelled things up with a header from Lampard's corner just after the half hour mark.
Chelsea, who played summer signings Eden Hazard and Marko Marin, went ahead when Lampard shot home from close range after 58 minutes.
DC United's Pontius equalised with 17 minutes to go and Johnson, of Seattle Sounders, won the game with a goal in injury time.
Source: PA
Source: PA