KABUL — The Taliban announced its first-ever cease-fire with Afghan forces on Saturday, accepting the Kabul government’s offer to halt fighting at the conclusion of the Muslim holy month of Ramadan.

The militant group, in a statement to reporters, said it would impose a truce with Afghan troops for three days but would continue attacks on foreign forces. The United States has about 15,000 troops in Afghanistan.

“Mujahideen are instructed to halt offensives against local opponents, but defend if they are attacked,” the group said. The truce will coincide with Eid al-Fitr, the religious holiday that marks the end of Ramadan.

The Taliban also said it may release prisoners, including government troops, provided they agree to refrain from fighting insurgents in the future, the statement said. It is not clear how many Afghan troops the Taliban holds captive.

The unprecedented step from the insurgent group, which has been fighting foreign troops and their local allies since 2001, comes two days after Afghan President Ashraf Ghani declared a week-long cease-fire beginning Tuesday and invited the Taliban to respond in kind. Ghani’s surprise announcement underscored his desire to establish a peace process that could put an end to a conflict that even his backers say cannot be won militarily.

Wadir Safi, a professor of international law and politics at Kabul University, said the Taliban’s decision was an acknowledgment that, despite its ability to pose a serious challenge to the state and maintain control over vast areas of rural Afghanistan, it would be equally unable to achieve its goals through force.

Taliban spokesman Zabiullah Mujahid said the truce was intended for the Eid holiday and would not affect the group’s larger objectives, which include the departure of foreign troops from Afghanistan. “Since our people are under occupation, jihad is incumbent on us,” he said in a message to The Washington Post.

Violence continued ahead of the cease-fire. According to local news reports, at least two dozen members of Afghan security forces were killed in Taliban attacks on Friday and Saturday. A Defense Ministry spokesman said Taliban members also were killed in fighting in 10 provinces.

“You can’t end 40 years of war in a few days, but this is definitely the best chance for a peace process at least since the U.S. surge” of troops under President Barack Obama in 2010-2011, said Vikram Singh, a former Pentagon and State Department official who is now a senior fellow at the Center for American Progress in Washington.

There was no immediate response to the Taliban’s statement from the U.S. military, which has a dual mission to support Afghan troops against the Taliban and, separately, conduct counterterrorism operations against extremists associated with the Islamic State and al-Qaeda. Ghani’s cease-fire offer did not cover Afghan operations against the Islamic State or other hard-line groups.

Last week, the U.S. military said it would observe the government cease-fire with the Taliban while continuing its activities against the Islamic State.

The Trump administration has increased the number of U.S. troops in Afghanistan in an effort to give a battlefield advantage to local forces, which continue to struggle despite more than a decade and a half of outside support.

Laurel Miller, who served as a senior U.S. official for Afghanistan and Pakistan under both Obama and President Trump and now works for the RAND Corporation, said that while any action to reduce violence was positive, the differing terms and timelines for the two parties’ cease-fires made the current circumstance a fragile one.

“I hope these cease-fires stick, but I would be cautious about too readily reaching any firm conclusions about the significance if they don’t,” she said. “Many peace processes are littered with failed cease-fires, but that doesn’t mean a process can’t ultimately succeed.”

The Trump administration has called repeatedly for a political resolution to the war. But it remains uncertain whether American officials will resume and expand discussions they have had intermittently with Taliban representatives since 2010. Under Trump, the State Department office that oversaw past attempts to establish a negotiating process was dismantled.

While the Taliban announced it would halt attacks in response to Ghani’s truce offer, it considers his government to be illegitimate and has said it would hold peace talks only with the United States.

Singh said the Trump administration would now need to develop a strategy for kindling peace talks and putting in place a bureaucratic framework that would put the weight of the American government behind a bid for peace.“The U.S. is now going to have to make some significant decisions about how this is going to go forward,” he said.

Sharif Hassan contributed to this report.