Multivariate analysis was conducted to explore the moist temperate forests of the Shangla district, Khyber Pakhtunkhwa. The prime objective was to quantitatively describe and differentiate the vegetation groups and the factors that determine the boundaries and composition of plant communities in the Shangla district. This was achieved by sampling all common species in a complex vegetation mosaic coinciding with local gradients in topography and soil distribution. Ward’s clustering dendrogram demonstrated four significant vegetation clusters with respect to environmental effects. These four major groups of the tree vegetation were superimposed on the ordination plane: 1. Pinus wallichiana, the dominant group associated with Abies pindrow; 2. Abies pindrow and the Picea smithiana group; 3. Dominant Cedrus deodara associated with the Pinus wallichiana, Abies pindrow, Picea smithiana, and Quercus baloot group; 4. Pinus roxberghii pure group. The key controlling factors for each group were the environmental characteristics (i.e., edaphic factors, topographic factors, soil physical properties, and soil nutrients). The results revealed elevation (p <0.001) to be the prominent factor in the composition of plant communities. Furthermore, pH, soil moisture, maximum water holding capacity, and soil physical properties (sand, silt, and clay) also showed a significant (p < 0.05) relationship with vegetation. The other environmental factor did not show a significant relationship with vegetation. Ward’s cluster dendrogram of understory species also demonstrated four groups. Group 1 comprises two subgroups, a and b, with the highest number of species, i.e., Digeteria sanguinalis, Fragaria nubicola, Verbascum Thapsus, Pinus wallichiana seedlings, and Polygonatum multiflorium, respectively. The second large group contains twenty-five species out of eight stands, and the dominant species was Tagetis minuta. Eighteen species out of six stands were found in group 3, which was considered the smallest group. Group 4 consisted of seven stands containing twenty-four species of ground flora, with Anaphalis scopulosa followed by Adiantum venustum as the dominant species. The environmental characteristics of the understory vegetation showed a resemblance with the tree communities. With the exception of elevation, the other factors did not show a significant correlation.