The short answer is that in the closing phases of the Second World War, Yugoslavian forces stopped just short of Trieste. The long answer is, well, somewhat more complicated and has to do with the demographics of the Eastern Adriatic shore, the role of Trieste in the Adriatic economy, and the role of Trieste in the narrative of "Unredeemed Italy."
It is undeniable that Trieste (commonly called “Triest” in English, although I’ll follow your lead in using the Italian spelling) is somewhat of a strange place. It seems unlikely that such a dense, prosperous city home to two hundred thousand people could exist stone’s throw from the Italian border (so close that, since Slovenia's entry in the Common European Market, many of Trieste's newer suburbs are outside Italy altogether). I’m going to offer an answer mostly from the Italian perspective, although I'll be happy to answer follow-ups or additional questions to the best of my knowledge and ability on the many items I will have necessarily skimmed over.
I’ll begin at a point in the not-too-distant past, as of the “First Completion” of Italian unity in 1870. The new Italian border with the Austro-Hungarian Empire was established at the Isonzo River, thus making the city of Trieste (together with Trento) one of the major points of contention in the “Irredentist” narrative purporting that Italian unity was not yet complete. But it's important to point out that this narrative did not necessarily have universal appeal: there existed a significant and largely dominant current within the Italian political class which instead preferred to solidify and consolidate that which had already been gained through the three very costly wars undertaken to found the Kingdom of Italy. So “irredentist” narratives would ebb and flow out of the popular discourse, not even relevant enough to stop the Italian government from entering a defensive alliance with the German and Austrian Empires in 1882. This “Triple Alliance” would continue to exist, however uncomfortably, right up until the outbreak of the First World War.
That's not to say there weren't serious tensions between Austria and Italy at the turn of the 20th century, however these tensions were typically framed around concerns about balance of power, rather than narratives of ethno-linguistic unity. Upon the outbreak of the war, it would be the Austrian disregard for provisions in the treaty regulating a balance of power in the Balkans that unleashed discontent in the Italian press and in the Italian government: the conquest of Serbia by the Austrian Empire should have triggered cessions to Italy, who shocked no one in tearing up the treaty when the Austrians wouldn’t commit to defining those cessions (the Italian press largely understood the cessions would include either Trent or Triest; but Austrians had clearly taken a calculated risk and chose to play deaf to Italian demands, even though the Germans were much more apprehensive and kept pushing to broker an Italian entry for some time even after the Italians and Austrians stopped talking). But even here, the “Irredentist Mood” was still not fervent enough to push Italy into the war until a year after the fighting broke out. It is only after Italy's entry in 1915 that irredentist language was quickly co-opted by the national press and the state propaganda machine, with “Trento e Trieste!” becoming a major rallying cry.
But what right did the Italian government have to claim Trieste to begin with?
National and cultural borders are funny things, in that they don’t really exist until someone chooses to draw them. The strict lines separating language and cultural groups are largely an invention of the industrial age on the one hand, and the nationalism that happened to emerge alongside it on the other. And even when those borders are drawn, belonging to a language or cultural group can nonetheless very often be linked to social or familial identity, as opposed to geographic location. In few places is this more evident than in the Eastern shore of the Adriatic.
According to the Imperial census of 1910, Trieste offers a demographic split fairly consistent with other large cities along the coast of Istria and Dalmatia: just over half the population was Italian-speaking, a quarter was Slovenian-speaking, and the remaining quarter consisted of speakers of the other languages of the Austrian Empire. Notably, only 1% claimed German as their first language, although we can assume many would have spoken it as a second language, even if we ultimately do not know how many individuals spoke two or more languages nor with what degree of fluency those languages were spoken (the census didn’t ask). Given that Trieste had by then consolidated in its role as the Austro-Hungarian Empire’s principal harbor, we can nonetheless assume that a fair share of residents would be multilingual. Interestingly, studies on the local dialect of Italian spoken in Trieste conducted in the 1950s note that over the course of the 19th century, the local Friulian dialect of spoken in Trieste had been gradually replaced by a local (“Colonial”) variant of the Venetian dialect. While Venetian-base dialects have been spoken along the whole coast of the Friuli and in cities of Istria and Dalmatia since the Middle Ages, its late coming to Trieste might signal social and economic ties to Venice and the Veneto were a fairly recent phenomenon (concurrent with the Veneto’s integration into the Austrian Empire, and Trieste’s growth as the Empire’s main export-harbor).
Indeed, it is undeniable that Trieste’s relevance is fairly recent phenomenon. In all of the the Republic of Venice’s history as sovereign of Istria and Dalmatia, the then-sleepy community of Trieste had been largely ignored. While legal accords, economic links, and occasionally military coercion led the Republic to establish overlordship over countless cities on Eastern Adriatic coast (including Capodistria, fourteen miles south of Trieste just over the promontory of Muggia) Trieste was instead allowed to exist largely undisturbed, its small mercantile class left to sort out its own tensions with the surrounding landowners (whose vineyards represented the city’s principal economic activity). In the early 15th century the landowners won out in the struggle for influence in the city (the opposite of what happened in most other Italian cities) and Trieste the Free Commune spent most of its modern history pledged to Austria (a small anomaly along a coastline dotted with cities flying the Venetian Banner of St. Mark).
The enlightened despotism of the mid-18th century would see Empress Maria Teresa of Austria take an interest in developing Trieste as the Empire’s main commercial entrepôt. Thus Imperial decrees abolished customs duties, enlarged the harbor, built shipyards, and built new public buildings to house representatives of an increasingly large and active government (as well as palaces to house imperial visits). After the Napoleonic Wars, Trieste’s growth was further helped along by the absorption of Northeast Italy into the Austrian Empire, which accelerated the decline of the city of Venice, Trieste's main competitor at the head of the Adriatic (while this decline was initially unintentional, incidents ranging from naval mutinies to popular uprisings eventually drove the Austrian government to intentionally neglect Venice in favor of Trieste). In the mid-19th century the seat of the Imperial navy was moved from Venice to Trieste, and the railroad arrived soon after, thus not only cementing not links to the Empire’s industrializing heartlands in Styria, but also political links to the “Triangle” of industrializing capitals (Vienna, Budapest, and Prague). In other words, Trieste had come to play a pivotal role in the imperial economy.
So while Trieste was an economically vibrant majority-Italian city, it was a modern and mostly "Austrian" invention. It was not a place which had played any significant part in the cultural and social narrative around which the unity of Italy had been constructed. No events significant to the nationalist narrative of the “History of Italy,” had ever taken place there. A mercantile class speaking an Italian dialect had existed throughout its history, but the city’s strongest economic ties were to Austria, and the strongest links to Italy were those that existed insomuch as it siphoned investment and manpower from the declining northeast.
Considerations on Trieste's pre-World Wars demographics continue below (as I am approaching the character limit)