Tamoxifen works primarily as an anti-estrogen in breast tissue, making it effective in treating and preventing breast cancer. Conversely, it acts as an estrogen agonist in the uterus and bones. Raloxifene, on the other hand, functions similarly in the breast tissue but does not stimulate the uterine lining, reducing the risk of endometrial cancer. Both drugs contribute to maintaining bone density, which is beneficial in preventing osteoporosis.