American warplanes also joined the five-hour clash with about 25 insurgents on Sunday evening in Laghman, a province of an eastern opium-producing region where U.S. forces have regularly fought with militants.
Acting on intelligence about the rebels' whereabouts, U.S. Marines "located the insurgents and an engagement ensued," a statement from the U.S. military said. "Two U.S. Marines were killed."
The names of the dead were withheld pending notification of next-of-kin.
A second statement said "two insurgents were confirmed killed and another 21 suspected dead."
There was no word on any wounded from either side.
The military said the Marines initially came under attack with small arms and rocket-propelled grenades from insurgents who split into two groups, one of which fled to a village and the other to a cave on a nearby ridge.
The two Marines died while clearing the cave after A-10 ground attack planes pounded the rebels holed up inside, the statement said. It didn't explain further.
Militants opposed to the U.S.-backed government of President Hamid Karzai have made good on pledges to ramp up their three-year-old insurgency after the melt of the winter's snow, carrying out a string of assaults and bombings that have killed dozens of Afghan and U.S. troops and government officials.
However, they have suffered heavy casualties, particularly where American warplanes have caught them in large groups on open ground.
The Marines died days after the bloodiest fighting in Afghanistan in nine months, when U.S. and Afghan forces including American warplanes clashed with large groups of insurgents in two southern provinces last week.
Sixty-four rebels, nine Afghan soldiers and an Afghan policeman were reported killed, while six American troops were among the wounded.
American commanders insist they are grinding the insurgents down and persuading villagers in a belt of territory along the Pakistani border to stop sheltering them.
They have also suggested that the currently 18,000-strong U.S.-led force could be trimmed after Sept. 18 parliamentary elections supposed to crown the country's democratic rebirth, depending on the success of a reconciliation plan which has prompted a string of former Taliban allies to give up the fight.
Sunday's deaths bring to 143 the number of American troops killed in and around Afghanistan since the start of Operation Enduring Freedom in 2001, according to U.S. Defense Department statistics.
The last U.S. soldier previously killed in action in Afghanistan died April 26 when his unit was ambushed in central Uruzgan province.