Warm olive oil in a large skillet over medium heat.
Soften the onion with a pinch of salt, stirring, until translucent, about 5 minutes.
Stir in garlic and red pepper flakes; cook until fragrant, about 30 seconds.
Pour in crushed tomatoes and add sugar. Season with salt and black pepper; stir to combine.
Simmer the sauce gently, uncovered, stirring occasionally, until slightly thickened, 15–18 minutes.
Meanwhile, boil spaghetti in generously salted water until al dente. Reserve 1/2 cup pasta water, then drain.
Toss drained pasta into the sauce. Splash in a little reserved pasta water to loosen; cook 1 minute.
Fold in most of the basil. Taste and adjust seasoning. Serve topped with Parmesan and remaining basil.