Ads. In case of Google, they run a program called adwords where you can buy ads for a particular keyword. When any user types a query and gets related ads to that keyword and then clicks on it. Google earns money. Same applies for bing, yahoo and few other search engines. Other than ads, they also offer other services from which they earn revenue.