The stock market, caught up in last-minute currents of yearend buying and selling, closed out 1977 with a small gain today.

The Dow Jones average of 30 industrials edged up .78 to 831.17, finishing the four-day trading week with a 1.30 gain.

For the year, the Dow lost 173.48 points, or 17.26 per cent. It was the first loss since it plunged 234.62 points, or 27.5 per cent in 1974. One year ago, the Dow finished at 1,004.65.

The Dow's setback also was the first in the first term of a Democratic president since it dropped 10.3 per cent when Woodrow Wilson took office in 1913.

Advances outnumbered declines by a 5-4 margin on the New York Stock Exchange, composite index of all its listed common stocks rose .07 to 52.50.

Big Board volume totaled23.56 million shares against 23.61 million the day before.

Nationwide turnover in NYSE-listed issues, including trades in those stocks on regional exchanges and in the over-the-counter market, came to 26.70 million shares.

At the American Stock Exchange, the market value index climbed . 97 to 127.89, finishing 1977 at a four-year high.

The starring role of lesser-known stocks all through the year was vividly illustrated by the Amex's index's 17 per cent gain while the Dow, made up of big-name blue chips, fell 17 per cent.

NYSE volume for the year totaled 5.27 billion shares, falling just short of the record of 5.36 billion established in 1976.

Analysts said the market's activity today was dominated by last-minute maneuvering by traders taking losses for 1977 tax purposes and institutions readying their portfolios for yearend reports.

In the economic news, the Commerce Department reported that its index of leading economic indicators turned downward in Novermber, posting a 0.2 per cent decline after four consecutive monthly gains.

But the drop in the index, which is designed to foreshadow future economic trends, seemed to come as no big surpise to investors.

Standard & Poor's index of 400 industrials posted a .16 gain to 104.71 for the day, while S&P's 500-stock composite index picked up .16 to 95.10.

No stock on the active list showed more than a fractional change as of the 4 p.m. close in New York.

International Business Machines shares, which have had a strong December since the company raised its dividend, gained 1/4 to 273. Other glamor issues were mixed.

In the blue chip sector, American Telephone Telegraph edged up 1/8 to 60 1/2, but Eastman Kodak lost 1/2 to 51 and Sears Roebuck was down 1/4 at 27 7/8.

In the over-the-counter market, the NASDAQ composite index gained .63 to 105.05.