BENGALURU, June 21 (Reuters) - Indian shares ended lower on Friday, once again succumbing to profit booking after hitting all-time highs, although they locked in a third straight week of gains powered by a rally in financials and the return of foreign investors.

The NSE Nifty 50 fell 0.28% to end at 23,501.1, while the S&P BSE Sensex lost 0.35% to finish at 77,209.80, but managed to eke out gains for the week.

However, the Nifty's 0.15% rise this four-day week was less than the 0.75% it rose last week and its 3.37% surge the week before. The index traded in a sub-300 point range for the second week in a row.

The small- and mid-caps were muted on the day, but also rose for a third straight week.

There will be profit booking near record high levels, especially when valuations across the markets are high, said Neeraj Dewan, director at Quantum Securities.

The near-term move will depend on India's budget in July, monsoon trajectory and upcoming earnings season, Dewan said.

Energy, consumer and auto stocks dropped between 0.6% and 1.25% on the day, while private banks snapped a four-session rally.

The bright spot was IT stocks, which gained 0.76% after U.S. peer Accenture gave an upbeat annual revenue growth forecast, signalling demand in the key U.S. market.

While down on the day, private banks gained 4.17% this week, the most among Nifty sectors, which Dewan said was due to "valuation comfort" and the return of foreign money.

Foreign inflows turned positive for the month as of June 20, data showed, with inflows of 109.23 billion rupees so far, compared with outflows of 255.86 billion rupees in May.

Besides financials, realty and telecom were top picks.

On the day, Hindustan Zinc gained about 3% on signing a pact with U.S.-based AEsir Technologies to develop zinc batteries.

JM Financial fell 4.6% after India's markets regulator barred the company from new mandates for bond issues until March 2025.

(Reporting by Bharath Rajeswaran and Kashish Tandon in Bengaluru; Editing by Janane Venkatraman, Savio D'Souza and Eileen Soreng )