Security was tight at the same harbour-front venue where two decades earlier, the last colonial governor, Chris Patten, tearfully handed back Hong Kong to Chinese rule at a rain-soaked ceremony.
Minor scuffles broke out under a blue sky as pro-democracy activists, some with banners bearing the words "Democracy. Self determination", and pro-Beijing groups taunted each other, with hundreds of police deployed on a traditional day of protest in Hong Kong.
Scores of democracy protesters were taken away by police, while several pro-China groups remained, cheering loudly and waving flags as though in victory.
"Long live China," they shouted in unison. "We support the police's law enforcement actions."
Britain returned Hong Kong to Chinese rule on July 1, 1997, under a "one country, two systems" formula which guarantees wide-ranging autonomy and judicial independence not seen in mainland China.
Beijing-backed civil servant Lam was chosen to be Hong Kong's next leader in March by a 1,200-person "election committee" stacked with pro-China and pro-establishment loyalists.
Xi's visit comes amid heightened tension between China and Hong Kong. Hong Kong's pro-democracy activists have been protesting against what they say is China's growing encroachment on the city's freedoms in a breach of the "one country, two systems" arrangement.
Beijing's refusal to grant universal suffrage to Hong Kong triggered nearly three months of street protests in 2014 and growing calls for independence for the city, in what many observers see as the most tumultuous post-handover period seen in Hong Kong .
Xi conceded on Friday the "one country, two systems" formula faces "new challenges" but that it shouldn't be handled with an "emotional attitude".
Upwards of 100,000 thousand protesters are expected to take to the streets for an annual march in the afternoon to mark the 20th anniversary of the handover.
(Reporting By James Pomfret, Venus Wu, William Ho, Editing by Anne Marie Roantree and Nick Macfie)
(Except for the headline, this story has not been edited by NDTV staff and is published from a syndicated feed.)