If using fresh tomatoes, bring a large pot of water to a boil. Make a small X in the bottom of each tomato and plunge into the boiling water until the skins are slightly loosened, 30 seconds to 2 minutes. Transfer to a bowl of ice water for 1 minute. Peel with a paring knife, starting at the X. If using frozen tomatoes, run each under warm water and peel or rub the skin off. Thaw in the refrigerator or defrost in the microwave until mostly thawed. Chop the tomatoes, reserving any juice.

Heat oil in a Dutch oven over medium heat. Add onions and cook, stirring, until beginning to brown, about 4 to 6 minutes. Add garlic and cook, stirring, for 1 minute. Add the tomatoes (and any juice), basil, thyme, oregano, salt, pepper, and sugar (if using). Bring to a boil. Reduce heat to maintain a simmer and cook until thickened to the consistency of pizza sauce, about 2 hours. Taste and season with additional salt, pepper, and/or sugar.

Transfer the sauce to a blender, add tomato paste, and blend until smooth. (Use caution when pureeing hot liquids.)