The objectives of this study involve the optimization of longitudinal porous fins of square cross-section using metaheuristic algorithms. A generalized nonlinear ordinary differential equation is derived using Darcy and Fourier's laws in the energy balance around a control volume and is solved numerically using RFK 45 method. The temperature of the base surface is higher than the fin surface, and the fin tip is kept adiabatic or cooled by convection heat transfer. The other pertinent parameters include Rayleigh number (100 ≤ Ra ≤ 10 4 ), Darcy number, (10 −4 ≤ Da ≤ 10 −2 ), relative thermal conductivity ratio of solid phase to fluid (1000 ≤ k r ≤ 8000), Nusselt number (10 ≤ Nu ≤ 100), porosity (0.1 ≤ φ ≤ 0.9). The impacts of these parameters on the entropy generation rate are investigated and optimized using metaheuristic algorithms. In computer science, metaheuristic algorithms are one of the most widely used techniques for optimization problems. In this research, three metaheuristic algorithms, including the firefly algorithm (FFA), particle swarm algorithm (PSO), and hybrid algorithm (FFA-PSO) are employed to examine the performance of square fins. It is demonstrated that FFA-PSO takes fewer iterations and less computational time to converge compared to other algorithms.