Heat 2 tablespoons olive oil in a large skillet over medium heat until the oil shimmers.
Add 4 large onions (thinly sliced, about 10 cups) to the skillet and spread them into an even layer.
Cook the onions, stirring every 3–5 minutes, until they are soft, translucent, and just beginning to brown, about 20 minutes. If they brown too quickly, reduce the heat to medium-low.
Stir in 3 tablespoons balsamic vinegar, 2 tablespoons brown sugar, 1 1/2 teaspoons finely chopped fresh rosemary (or 1/2 teaspoon dried), 1/4 teaspoon kosher salt, and 1/4 teaspoon freshly ground black pepper, scraping up any browned bits from the pan.
Continue to cook, stirring every few minutes, until most of the liquid has evaporated, the onions are dark brown, and the mixture is reduced to about 3/4 cup, about 40 minutes more. Adjust the heat as needed to keep the onions from burning.
Remove the skillet from the heat and let the onion jam cool to room temperature.
Transfer the cooled jam to a glass jar or airtight container and refrigerate for up to 1 week.