Cook the spaghetti according to package instructions until al dente. Drain and set aside.
In a large skillet, heat olive oil over medium heat. Add chopped onion and sauté until translucent, about 5 minutes. Stir in minced garlic and cook for an additional minute.
Add the ground beef to the skillet, breaking it up with a spoon. Cook until browned and no longer pink, about 6-8 minutes. Drain excess fat if necessary.
Stir in crushed tomatoes, tomato sauce, sugar, basil, oregano, salt, and black pepper. Bring the mixture to a simmer and let it cook for 15 minutes, stirring occasionally.
Preheat your oven to 350°F (175°C).
In a large mixing bowl, combine the cooked spaghetti with the meat sauce until well coated. Transfer the mixture to a greased 9x13-inch baking dish.
Sprinkle shredded mozzarella and grated Parmesan cheese evenly over the top.
Bake in the preheated oven for 25-30 minutes, or until the cheese is bubbly and golden brown.
Remove from the oven and let it cool for a few minutes. Garnish with fresh basil leaves if desired before serving.