President Samora Machel of Mozambique, a dedicated Marxist who has turned to the United States for economic and diplomatic support to bolster his war-battered and economically hard-pressed southern Africa nation, was welcomed warmly at the White House yesterday by President Reagan.

Their two-hour meeting, including a working luncheon, may rank as the most improbable political encounter for either president to date, given Reagan's strong anticommunist sentiments and Machel's equally strong commitment to Marxism and political ties to the Soviet bloc.

Conservative groups strongly oppose Machel's visit, and Sen. Malcolm Wallop (R-Wyo.) and Rep. Danny L. Burton (R-Ind.) introduced legislation to provide "noncommunist resistance forces" fighting in Mozambique with as much as $5 million in aid during fiscal 1986 and end U.S. economic assistance to Mozambique.

Administration officials have strongly defended the controversial economic aid and emergency assistance program to Mozambique, which totals about $40 million this year. They say the United States is simply responding to Machel's desire to move from socialist domestic policies and reliance on Moscow abroad.

Despite the two presidents' widely divergent ideological views, a senior administration official briefing reporters after the meeting said they had discussed "at some length" merits of the free enterprise system and "approaches that work and don't work" in economic development in "a very positive atmosphere."

In a short departure statement, Reagan said the meeting was meant to underscore U.S. determination to continue playing "an active and constructive role" in southern Africa in its effort to promote peace and democracy in that troubled region.

Reagan hailed Machel for taking "a step toward peace" in signing the Nkomati accord with white-ruled South Africa in March 1984.

In it, Mozambique pledged to halt cross-border raids by black nationalist guerrillas into South Africa, and Pretoria agreed to stop backing the Mozambique Resistance Movement (Renamo).

To the distress of the Mozambican delegation, the United States gave two-week visas to three Renamo officials to attend the World Anti-Communist League conference in Dallas last week. The three lobbied on Capitol Hill this week against Machel's visit, arguing that, without Western aid, his government would have fallen by now.

In his statement, Reagan also hailed Mozambican decisions to join the World Bank and the International Monetary Fund, seek western investment and strengthen the private sector. Reagan described these steps as "a formula for economic advancement."

Machel said that the meeting was "very positive, fruitful and constructive" and that it had established "a solid basis for long-term cooperation in all fields" between the two countries.

Noting Mozambique's considerable natural resources, Machel said, "We seek the participation of the United States and its private sector in putting those resources at the service of our economic and social development."

Machel also stressed that Mozambique remains "an independent, nonaligned" nation deeply attached to its 10-year-old independence from Portugal. He pledged to continue strict compliance with the Nkomati accord to help stabilize southern Africa.

On Monday, just before leaving for his visit here, Machel announced that he has documentary evidence that South Africa is aiding Renamo in violation of the Nkomati accord, described by the senior administration official as "a major milestone" in the U.S. search for peace in southern Africa.

The official said there is "obviously . . . deep concern" about the South African accord violations, which Pretoria confirmed yesterday while charging that Mozambique also is violating it. The official said he does not believe that the pact is in serious jeopardy.

"We will do what we can do to encourage the parties to get to the bottom of this and to encourage the South Africans to clear up the allegations," the official said, noting that the United States has contacted Pretoria about the issue.