Finely chop the onion and mince the garlic.
Heat the olive oil in a large saucepan or pot over medium heat.
Add the chopped onion and sauté until it becomes translucent, about 5-7 minutes.
Add the minced garlic and cook for another 1-2 minutes, until fragrant.
Add the whole peeled tomatoes (with their juice) to the pot.
Use a wooden spoon or spatula to break the tomatoes into smaller pieces.
Add salt, black pepper, dried oregano, dried basil, and red pepper flakes (if using).
Stir well to combine all the ingredients.
Bring the sauce to a simmer over medium-high heat.
Reduce the heat to low and let it simmer gently for about 30 minutes, stirring occasionally.
If desired, add sugar to balance the acidity of the tomatoes.
For a smoother sauce, use a blender or immersion blender to puree the sauce to your desired consistency.
Stir in the chopped fresh basil leaves.
Simmer for an additional 5 minutes to allow the flavors to meld.
Use the marinara sauce immediately with pasta, pizza, or as a dipping sauce.