  We use the SED-fitting code Prospector to reconstruct the nonparametric star
formation history (SFH) of massive ($\log M_*>10.3$) star-forming galaxies
(SFGs) and quiescent galaxies (QGs) at redshift $z_{\rm{obs}}\sim2$ to
investigate the joint evolution of star-formation activity and structural
properties. We find significant correlations between the SFH of the galaxies
and their morphology. Compared to extended SFGs, compact SFGs are more likely
to have experienced multiple star-formation episodes, with the fractional mass
formed during the older ($\ge1$ Gyr) episode being larger, suggesting that
high-redshift SFGs assembled their central regions earlier and then kept
growing in central mass as they become more compact. The SFH of compact QGs
does not significantly differ from the average for this category, and shows an
early burst followed by a gradual decline of the star formation rate. The SFH
of extended QGs, however, is similar to that of post-starburst galaxies and
their morphology is also frequently disturbed. Knowledge of the SFH also
enables us to empirically reconstruct the structural evolution of individual
galaxies. While the progenitor effect is clearly observed and accounted for in
our analysis, it alone is insufficient to explain the observed structural
evolution. We show that, as they evolve from star-forming phase to quiescence,
galaxies grow massive dense stellar cores. Quenching begins at the center and
then propagates outward to the rest of the structure. We discuss possible
physical scenarios for the observed evolution and find that our empirical
constraints are in good quantitative agreement with the model predictions from
dissipative accretion of gas to the center followed by massive starbursts
before final quiescence (wet compaction).
