We consider generating maximally entangled states (Bell states) between two qubits coupled to a common bosonic mode, based on f-STIRAP. Utilizing the systematic approach developed in New J. Phys. 19 093016 (2017), we quantify the effects of non-adiabatic leakage and system dissipation on the entanglement generation, and optimize the entanglement by balancing non-adiabatic leakage and system dissipation. We find the analytical expressions of the optimal coupling profile, the operation time, and the maximal entanglement. Our findings have broad applications in quantum state engineering, especially in solid-state devices where dissipative effects cannot be neglected.