Botanically it's a fruit, and specifically a berry.
To a botanist, a fruit is the part of a flowering plant that grows from the flower and holds the seeds. A tomato fits perfectly, so it's a fruit. More precisely, it's a berry: a fleshy fruit that develops from a single flower's ovary and has seeds inside. By the same rule, cucumbers, peppers, eggplants and pumpkins are fruits too.
Cooks see it differently. In the kitchen, "vegetable" means a savory plant food used in main dishes, and "fruit" means something sweet. Tomatoes go into salads, sauces and soups, not fruit salad, so they're treated as vegetables.
The question even reached the US Supreme Court. In the 1893 case Nix v. Hedden, an importer argued tomatoes were fruit to avoid a tax on vegetables. The court ruled that in everyday use tomatoes are vegetables, so the tax applied.
So both answers are right, depending on whether you're asking a botanist or a cook.