Bring a large pot of salted water to a boil and cook the spaghetti according to the package instructions until al dente. Drain, reserving ½ cup of pasta water.
Heat the olive oil in a large skillet over medium heat. Add the chopped onion and sauté for 3–4 minutes until softened.
Stir in the minced garlic and cook for 30 seconds until fragrant.
Add the tomato sauce, Italian seasoning, salt, and black pepper. Simmer for 10–15 minutes, stirring occasionally.
Add the cooked spaghetti to the sauce and toss until evenly coated. Add a little reserved pasta water if needed to loosen the sauce.
Cook for another 1–2 minutes to allow the flavors to combine.
Serve hot, topped with grated Parmesan cheese and fresh basil if desired.