the first result I clicked before is highlighted - how does the search engine knows?
Visited links are highlighted because your browser keeps track of them in the browser history, not because the sites are tracking you.
There is a special CSS selector for that. When your browser renders a page, it looks for links with the
:visited CSS selector and checks if the link appears in your history. If it does, the link is displayed according to the selector rules (which by default is a different text color).
The website itself cannot read this value, so it can't track that you visited the link before. (At least it's supposed to not know that you visited it. In the past there have been several vulnerabilities known as history leaks that allow websites to reverse-engineer the sites you visited.)
To stop visited links from displaying differently in Firefox, you can go to
about:config and set
layout.css.visited_links_enabled = false. If you don't want Firefox to keep track of visited sites at all, you can disable the browser history in your preferences under the Privacy tab.