Images from chest X-rays (CXR) are thought to help observe and research various kinds of pulmonary illnesses. Several works were suggested in the literature for recognizing unique lung diseases, and only a few studies were focused on developing a model to identify joint classes of lung diseases. A patient with a negative diagnosis for one condition may have the other disease, and vice versa. However, since many illnesses are lung-related, a patient can have multiple illnesses simultaneously. This paper proposes a deep learning (DL)-based pre-trained transfer learning (TL) model for effectively detecting and classifying the multiclass diseases of lung CXR images. The system involves five phases: preprocessing, dataset balancing, feature learning, feature selection, and multiclass classification. Firstly, the CXR images are preprocessed by performing filtering, contrast enhancement, and data augmentation. After that, the dataset balancing is performed using the Synthetic Minority Oversampling Technique (SMOTE). Next, the features are learned using a spatial and channel-attention-based Xception Network (SCAXN). The optimal features are selected using nonlinear decreasing inertia weight-based rock hyraxes swarm optimization (NIWRHSO). Finally, the multiclass classification uses a soft sign-incorporated bidirectional gated recurrent unit (SBIGRU). Two public datasets, COVID-19 Radiography (C19RY) and Tuberculosis CXR (TB-CXR), have been obtained from Kaggle, and the outcomes confirmed that the proposed system attains superior results to prevailing methods.