Summary Background Heparins substantially reduce the risk of thromboembolic complications after total hip or knee replacement. However, they can be given only by injection and have several other drawbacks. We did a multicentre, randomised, double-blind study to examine the dose-response relation of subcutaneous melagatran, a direct thrombin inhibitor, followed by oral ximelagatran as thromboprophylaxis after total hip or knee replacement. We aimed to compare the efficacy and safety with that of dalteparin. Methods Of 1900 patients, 1495 were assigned to four dose categories of subcutaneous melagatran from just before surgery (1·00 mg, 1·50 mg, 2·25 mg, or 3·00 mg twice daily) followed from the day after surgery by oral ximelagatran (8 mg, 12 mg, 18 mg, or 24 mg twice daily). 381 patients were assigned subcutaneous dalteparin 5000 IU once daily, from the evening before surgery. Bilateral venography was done at 7–10 days, and clinically suspected venous thromboembolism (VTE) was confirmed radiologically. The primary endpoint was the rate of deep-vein thrombosis and pulmonary embolism (PE). Analyses were by intention to treat. Findings 1876 patients underwent total replacement of hip (n=1270) or knee (n=606); evaluable venograms were obtained in 1473 (79%). Four patients without evaluable venograms had PE. Overall, a significant dose-dependent decrease in VTE was seen with melagatran/ximelagatran (lowest to highest group: 111 [37·8%] 70 [24·1%], 71 [23·7%], and 43 [15·1%]; p=0·0001); there were also significant relations for both total hip and total knee replacement individually. The frequency of VTE was significantly lower with the highest dose of melagatran/ ximelagatran than with dalteparin (15·1% vs 28·2%, p<0·0001). There were no reoperations due to bleeding and no critical organ bleeding. Excessive surgical bleeding was uncommon but more frequent in the highest dose group. Interpretation This sequential therapy was effective and safe in patients undergoing major joint replacement surgery. The findings should be confirmed in a large phase III trial.