In its first major action to relieve the long recession, Congress yesterday gave final approval to a $4.6 billion jobs bill, and President Reagan quickly signed it, but not before money for unemployment benefits ran out in a dozen states, including Virginia.

The measure, which was tied to a $5 billion appropriation to continue funding for jobless benefits in 27 states and the District of Columbia, reached the president's desk late in the evening, according to spokesmen, and Reagan signed it shortly thereafter.

Although initially he had opposed spending for jobs creation, Reagan reversed course under pressure from both parties in Congress, and made a $4.3 billion jobs offer early last month, paving the way for what amounted to a bipartisan compromise on spending for recession relief.

But enactment did not come in time to keep Colorado, Montana, Vermont and Virginia from running out of money on Wednesday or to prevent a similar cutoff yesterday for Pennsylvania, West Virginia, Kentucky, Tennessee, Illinois, Michigan, Ohio and Missouri, according to the Labor Department. The Virgin Islands ran out of benefit money on Tuesday.

Eight other states and territories and the District of Columbia faced exhaustion of benefit funds by today, although Labor Department spokesman Jack Hashian said that the District had made plans to borrow, if necessary, in order to keep benefit money flowing. Hashian also quoted Virginia officials as saying they would be able to meet most payments for three or four days.

Hashian said the states had been advised that, while the federal government could not officially lend them any more money for jobless benefits until the bill was signed, they could make the payments from state funds on a "prudent risk" assumption that the federal loans would be sanctioned eventually.

In other words, Hashian said, it looks as though action came "in the nick of time without any serious interruption of benefits."

The jobs bill, including the unemployment benefits money, was sent to Reagan after the House approved, by voice vote, a conferees' compromise on how many new jobs would be targeted to areas of highest unemployment. The targeting compromise, channeling roughly $2.1 billion of the $4.6 billion to these hardest-hit areas, was approved by the Senate earlier in the week.

Aside from about $200 million for food, shelter and other humanitarian aid for victims of the recession and several hundred million dollars for other social services, most of the money would go for construction, repair, maintenance and public service jobs under existing federal programs.

Some is earmarked for projects in areas represented by influential lawmakers, especially appropriations committee members who drafted the legislation--one of the few old-fashioned spending bills to make its way through Congress since Reagan took office.

Along the way it also became an attractive vehicle for assorted "riders," including an attempted amendment in the Senate to repeal tax withholding on interest and dividends, eventually shoved aside.

There is no official estimate of how many jobs will be created by the bill, although some lawmakers have used figures ranging as high as 500,000--which, they concede, would employ only a small fraction of the roughly 11.5 million unemployed Americans.

Although the measure was larger than Reagan wanted, the compromise version, minus the Senate's revenue-sharing proposal, was smaller than the original versions approved by the two houses: $5.2 billion by the Senate and $4.9 billion by the House.