Investigators have been probing SAP's work for the department for several years, alleging procurement rules were broken and contracts entered unlawfully.
The Special Investigating Unit (SIU) and Department of Water and Sanitation (DWS) said in a statement that the SIU had confronted SAP and the DWS with evidence of wrongdoing over license and support agreements between 2015 and 2016.
An order from the Special Tribunal - a court established by President Cyril Ramaphosa's government to fast-track recovery of misspent or stolen public money - made on Tuesday said SAP had to pay DWS around R263m within five court days.
A further amount of roughly R83m that SAP paid to third-party software companies is still under dispute, with the parties told to file affidavits on whether that amount should also be repaid.
SAP said in a statement that it had reached a settlement with the SIU and DWS. It said the department remained an SAP customer and that it was committed to maintaining a robust compliance programme.
SAP, which has a market value of more than $130bn, in 2018 admitted to misconduct over deals with South African state firms during former president Jacob Zuma's tenure.
Reuters, the news and media division of Thomson Reuters, is the world's largest multimedia news provider, reaching billions of people worldwide every day.Go to: https://www.reuters.com/