President Reagan, expressing misgivings, signed an expensive five-year farm bill yesterday that he said would help restore U.S. agricultural dominance in export markets.

"This legislation will help put America's farmers back in a competitive position in world markets," Reagan said in a White House ceremony attended by about 100 farm-state legislators.

Reagan also signed a bill that orders a restructuring of the Farm Credit System and gives the Farm Credit Administration more regulatory power. It could lead to last-resort federal bailout money for the farmer-owned lending network.

The new farm law, despite a three-year cost estimated at $2 billion more than the administration's $50 billion target, will lower the price support floors under basic commodities while maintaining high levels of income subsidies to help farmers through a transition to "market-oriented" production.

Under the price-support system, if market prices fall below specified floors for wheat, corn, rice and cotton, the farmer can obtain a government loan at the support rate. If prices do not rise, the farmer can forfeit his crop collateral to the government and keep the loan money, meaning effectively that the government has bought the crop at the support rate. Administration officials argue that higher U.S. support rates encourage foreign competition and cut U.S. farmers out of world markets.

The income supports, calculated on market prices and farmers' production costs, would continue at or above the record highs reached in two of the last three years. Legislators insisted on the high subsidy levels as the price for bowing to administration demands for lower price-support rates.

Throughout the year of intense political grappling over farm policy, the debate over price and income supports was punctuated by frequent administration threats of veto if Congress did not produce a more austere, market-oriented bill.

Reagan yesterday gave lawmakers credit for a "good faith" effort to cut program costs, which escalated during the year amid falling prices, slumping exports and severe credit problems in the Farm Belt.

The president did not refer directly to the political side of the debate. Republicans feared that if Reagan made good on his veto threats, a farm-state backlash next year could endanger GOP control of the Senate and cause party setbacks in the House. Nine Senate Republicans from major farm states are up for reelection in 1986.

"Our reforms will provide new hope for America's hard-working farmers," Reagan said. "If things are not going right down on the farm, things cannot continue to go well in our cities."

The president said he thought Congress could have done more to keep farm program costs down. But in a later teleconference with Agriculture Secretary John R. Block, he said the extra cost "is what is necessary if we are going to do the job."

Even with the president's generally upbeat assessment of the legislation, Block said that it would not be enough to stop the flow of failed farmers out of business this winter. "There is no question but what we will lose some more farmers," the secretary told reporters.

But Reagan and Block said the farm bill, along with the farm-credit measure, will provide more flexibility for lenders to help farmers over some rough spots. The Farm Credit System, which holds about one-third of the country's $214 billion farm debt, will be required to move assets from healthy districts to needier ones where falling land values have jeopardized thousands of loans.

Reagan and Block also expressed displeasure with other provisions of the farm bill related to the dairy support program, sugar import quota requirements and congressionally mandated subsidies to stimulate exports, which have fallen by about $12 billion in four years.

While the administration did not get precisely what it wanted on the dairy program, Congress did agree to reductions in price supports that could push the federal floor from the current $11.60 to $10.10 per hundredweight by the end of Reagan's second term. Also against administration wishes, Congress approved an "assessment" on dairy farmers to help pay for herd buyouts by the government to cut milk output.

Reagan and Block also spoke in glowing terms of the conservation section of the new farm law, which will create a "reserve" of up to 45 million acres and bar federal program benefits to farmers who plow up erodible land or convert wetlands to cropping. The conservation reserve would pay farmers to remove highly erodible land from production on a long-term basis.

Agriculture Department officials estimate overall cost of the five-year bill, which includes food stamps and research, at about $110 billion.