Traditionally, it seems that it ended gradually over time until capitalism* eventually rose above it, as new laws were created to favor merchants - but when did it legally start to end in most european countries?
*Which some believe was always present and underlying all through out history, and there are others that don't believe that. I think that's still up for debate, but it strikes me as semantical. Anyway, question is about feudalism.
It entirely depends which of the myriad definitions of "feudalism" you're applying. The supplanting of Feudalism by Capitalism is indeed a feature of traditional Marxian historical narrative, but most modern analysis has much more nuance, even if it is conducted through a Marxian lens. This is rendered more difficult by the fact that Feudalism, in one of its most popular definitions (a monarch parcels out lands to aristocrats, who in the popular imagination then proceed to oppress and exploit the peasants) was never the dominant economic and political system in Europe. Many scholars dismiss the value of the word altogether, and this sub even held an AMA about it a few years ago.
Even if we do construct a broad definition of feudalism more in-line with the nuances of how medieval society actually functioned, what sort of legal and social developments would mark the end of such a broad social construct? After having defined what specific characteristics define feudalism for us, we would then have to then evaluate if and when legal and/or social constructs began being devised in order to end whatever it is that we have defined.
From your post, it would seem that you are interested in the shift in comparative economic power and enfranchisement away from landholders to capital owners. Or rather, because land can be classified as capital, owners of financial capital. But this was not a uniform shift across Europe, nor was it one strictly defined by legal challenges to the "Feudal Order." Indeed, agriculture continued to be the largest economic activity in Europe right up to the Industrial Revolution (otherwise it wouldn't have been much of a revolution). This means that land owners continued to be influential long after whatever end we might assign to the "Middle Ages." In England, a class of politically active financiers began making themselves heard towards the very end of the 18th century and the early years of the 19th century (David Ricardo, one of the founders of the school of thought now classified as Classical Economics, was himself a successful trader of early financial instruments). Over centuries, trade across the Atlantic and with the rest of Europe had allowed the English mercantile class to slowly accrue wealth and influence in their own country which was comparatively greater than that enjoyed by their peers in the rest of Europe (exept for maybe the Dutch, who offer a similar economic developmental example). However, here we are not talking about the real or imagined system of "Feudalism." But even turning back the clock to any year we might classify as "Medieval," we will find politically enfranchised and influential investors of simpler financial contracts and instruments in the cities of the Mediterranean, foremost in Italy. In Florence, these financiers could exert political influence and benefit from political representation through their guild (and other guilds could also represent financial investors, however this would only really desirable for people investing in a single industry) and a banking dynasty would even grow powerful enough to dismantle the Florentine Republic (the Medici). At their height, the politically enfranchised class of the Maritime Republics of Venice, Genoa, and Pisa could also be expected to be heavily, if not wholly, invested in commercial enterprises. It is indeed during the period of decline of the Italian mercantile cities that multigenerational wealth slowly diverts away from commerce and trade in favor of land ownership, a preference which in later centuries would seriously hamper industrialization.
All this is to say that we cannot easily define when feudalism would "legally start to end" across Europe. Aristocratic privileges in the form of lenient taxes, prerequisites for political appointments, as well as formal and informal support networks, would continue to exist in many countries up until the 18th century. But this certainly doesn't mean that the strict hierarchy and economic simplicity of the "feudal pyramid" existed prior to that point; rather, this imagined pyramid was never really the defining feature of political organization in Europe in the first place.