Peanuts, owing to their composition of complex carbohydrates, plant protein, unsaturated fatty acids, and essential minerals (magnesium, iron, zinc, and potassium), hold significant potential as a vital component of the human diet. Additionally, their low water requirements and nitrogen fixation capacity make them an appropriate choice for cultivation in adverse environmental conditions. The germination ability of seeds profoundly impacts the final yield of the crop; assessing seed viability is of extreme importance. Conventional methods for assessing seed viability and germination are both time-consuming and costly. To address these challenges, this study investigated Visible–Near-Infrared Spectroscopy (Vis/NIR) in the wavelength range of 500–1030 nm as a nondestructive and rapid method to determine the viability of two varieties of peanut seeds: North Carolina-2 (NC-2) and Spanish flower (Florispan). The study subjected the seeds to three levels of artificial aging through heat treatment, involving incubation in a controlled environment at a relative humidity of 85% and a temperature of 50 °C over 24 h intervals. The absorbance spectra noise was significantly mitigated and corrected to a large extent by combining the Savitzky–Golay (SG) and multiplicative scatter correction (MSC) methods. To identify the optimal wavelengths for seed viability assessment, a range of metaheuristic algorithms were employed, including world competitive contest (WCC), league championship algorithm (LCA), genetics (GA), particle swarm optimization (PSO), ant colony optimization (ACO), imperialist competitive algorithm (ICA), learning automata (LA), heat transfer optimization (HTS), forest optimization (FOA), discrete symbiotic organisms search (DSOS), and cuckoo optimization (CUK). These algorithms offer powerful optimization capabilities for effectively extracting relevant wavelength information from spectral data. Results revealed that all the algorithms demonstrated remarkable accuracy in predicting the allometric coefficient of seeds, achieving correlation coefficients exceeding 0.985 and errors below 0.0036, respectively. In terms of execution time, the ICA (2.3635 s) and LCA (44.9389 s) algorithms exhibited the most and least efficient performance, respectively. Conversely, the FOA and the LCA algorithms excelled in identifying the least number of optimal wavelengths (10 wavelengths). Subsequently, the seeds were classified based on the wavelengths selected via the FOA (10 wavelengths) and (DSOS (16 wavelengths) methods, in conjunction with logistic regression (LR), decision tree (DT), multilayer perceptron (MP), support vector machine (SVM), k-nearest neighbor (K-NN), and naive Bayes (NB) classifiers. The DSOS–DT and FOA–MP methods demonstrated the highest accuracy, yielding values of 0.993 and 0.983, respectively. Conversely, the DSOS–LR and DSOS–KNN methods obtained the lowest accuracy, with values of 0.958 and 0.961, respectively. Overall, our findings demonstrated that Vis/NIR spectroscopy, coupled with variable selection algorithms and learning methods, presents a suitable and nondestructive approach for detecting seed viability.