Difficult question to answer since it depends on so many things, and possible problem areas.
Probably the key element is that management
(as high as possible) must understand that it’s in trouble, and be willing to fix it, even at the potential cost of losing face.
Within that framework, what’s needed is a really good project or program manager. This is a difficult thing for many people to understand, since the project manager’s job is not primarily technical, it’s keeping track of all of the various project details, especially as they relate to one another. Some of the more successful rescues I’ve seen or heard about (my wife is a program manager) comprise a team of a schedule-type manager with a technical manager so that each of them can keep the other on-track with respect to each other’s specialties.
Hope that helps,